Take a number and shuffle its decimal digits into any order you like. Some of the numbers you can spell that way are divisible by - count them.
To be counted, a number must use exactly the digits of , each as many times as has it, must not start with a zero, and must be divisible by . Two shuffles that spell the same number count once: can be shuffled into , and , and no others, however you swap its two identical twos.
Input
First line of input will be a single integer - the number of testcases.
Each of the next lines contains two integers and .
Output
For every testcase print a single line with how many different numbers can be spelled from the digits of that have no leading zero and are divisible by .
Example
3 104 2 223 4 7067678 8
3 1 47
From the numbers without a leading zero are , , and , and all but are even. From only is divisible by . The third testcase has of them.
Constraints
This problem is based on Roman and Numbers, problem 401D from Codeforces Round 235, by Mike Mirzayanov and the Codeforces team. The statement here is our own.