digitsum minimize

You are given positive integers N and D. You may perform operations of the following two types:

add D to N, i.e. change N to N+D
change N to digitsum(N)
Here, digitsum(x) is the sum of decimal digits of x. For example, digitsum(123)=1+2+3=6, digitsum(100)=1+0+0=1, digitsum(365)=3+6+5=14.

You may perform any number of operations (including zero) in any order. Please find the minimum obtainable value of N and the minimum number of operations required to obtain this value.

Input
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first and only line of each test case contains two space-separated integers N and D.
Output
For each test case, print a single line containing two space-separated integers — the minimum value of N and the minimum required number of operations.

Constraints
1≤T≤10
1≤N,D≤1010

Example Input
3
2 1
9 3
11 13
Example Output
1 9
3 2
1 4


Can someone help me with this problem?
can someone help me with this problem?
I am getting wa in 4/8 subtasks.
mee too
Topic archived. No new replies allowed.