As you know that sometimes base conversion is a painful task. But still there are some interesting facts in bases.
For convenience let's assume that we are dealing with the bases from 2 to 16. The valid symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
. You can safely assume that all the numbers given in this problem are valid.
For example, 67AB is not a valid number of base 11, since the allowed digits for base 11 are 0 to A.
Now in this problem you are given a base, an integer K and a valid number in the base which contains distinct digits. You have to find the number of permutations of the given number which are divisible by K. K is given in decimal.
For this problem, also assume that numbers with leading zeroes are allowed. So, 096 is a valid integer.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a blank line. After that there will be two integers, base (2 ≤ base ≤ 16) and K (1 ≤ K ≤ 20). The next line contains a valid integer in that base which contains distinct digits. The length of the integer will not be more than 12.
Output
For each case, print the case number and the desired result.
Sample
Sample Input | Sample Output |
---|---|
3 2 2 10 10 2 5681 16 1 ABCDEF012345 | Case 1: 1 Case 2: 12 Case 3: 479001600 |