CF1884A.Simple Design

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Simple Design

A positive integer is called kk-beautiful, if the digit sum of the decimal representation of this number is divisible by kk^{\dagger}. For example, 92729272 is 55-beautiful, since the digit sum of 92729272 is 9+2+7+2=209 + 2 + 7 + 2 = 20.

You are given two integers xx and kk. Please find the smallest integer yxy \ge x which is kk-beautiful.

^{\dagger} An integer nn is divisible by kk if there exists an integer mm such that n=kmn = k \cdot m.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The only line of each test case contains two integers xx and kk (1x1091 \le x \le 10^9, 1k101 \le k \le 10).

Output

For each test case, output the smallest integer yxy \ge x which is kk-beautiful.

Note

In the first test case, numbers from 11 to 44 consist of a single digit, thus the digit sum is equal to the number itself. None of the integers from 11 to 44 are divisible by 55.

In the fourth test case, the digit sum of 777777 is 7+7+7=217 + 7 + 7 = 21 which is already divisible by 33.

Samples

6
1 5
10 8
37 9
777 3
1235 10
1 10
5
17
45
777
1243
19

在线编程 IDE

建议全屏模式获得最佳体验