Problem G. Remove This Problem

Time limit: 5 seconds

Problem

(No problem statement.)

Input

The input starts with an integer n specifying the number of test cases.
Each case consists of a positive integer N with at most 100 digits and a positive integer M at most 1000, both on a single line.
Our target is to remove digits from N in order to convert it into a number divisible by M.
We assume that if you remove all digits from N, it gives 0 and is divisible by M.

Output

For each test case, print on a single line the minimum number of digits we need to remove from N, so that the resulting number is divisible by M.

Sample Input

3
360000000000000000000000000000 10
1234567891011121314151617181920 3
23010692543023 23

Sample Output

0
0
2

Author

Chan Ho Leung