{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"As you know that sometimes base conversion is a painful task. But still there are some interesting facts in bases.\n\nFor convenience let\u0027s 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.\n\nFor example, **67AB** is not a valid number of base **11**, since the allowed digits for base **11** are **0** to **A**.\n\nNow 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.\n\nFor this problem, also assume that numbers with leading zeroes are allowed. So, **096** is a valid integer."}},{"title":"Input","value":{"format":"MD","content":"Input starts with an integer **T (\u0026#8804; 100)**, denoting the number of test cases.\n\nEach case starts with a blank line. After that there will be two integers, **base (2 \u0026#8804; base \u0026#8804; 16)** and **K (1 \u0026#8804; K \u0026#8804; 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."}},{"title":"Output","value":{"format":"MD","content":"For each case, print the case number and the desired result."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\n\n2 2\n10\n\n10 2\n5681\n\n16 1\nABCDEF012345\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1: 1\nCase 2: 12\nCase 3: 479001600\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}