TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

Given a string s and a positive integer d you have to determine how many permutations of s are divisible by d.

Input Format

First line of the input contains one integer T the number of test cases. Each of the test cases is one line containing s and d separated by a single space.

Output Format

For each test case output contains an integer the number of permutations of s that are divisible by d.

Sample Input 1

3
000 1
1234567890 1
123434 2

Sample Output 1

1
3628800
90

Hints

Problem Source

Migrated from old NTUJ.

IIUPC 2006

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 200