| EPT Solving Cup 6.0 |
|---|
| Finished |
London, 1891. Sherlock Holmes wants to send a secret message to Dr. Watson.
There are $$$N$$$ identical iron posts in a courtyard. Holmes may write one digit (0–9) on any post and may leave some posts blank. Later, Watson will see the courtyard, but because of fog and moved lanterns, he cannot know the order of the posts. He only knows how many times each digit appears. The order does not matter.
Before Watson arrives, a clerk may use a cipher wheel. Every time the wheel is used, each written digit $$$d$$$ is replaced by $$$ d \rightarrow (a \cdot d + b) \bmod 10 $$$ where:
The wheel may be used any number of times (possibly zero). Each use can choose any $$$a \in S_a$$$ and any $$$b \in S_b$$$. So the final effect is a composition of such transformations.
Holmes and Watson know $$$N$$$, $$$S_a$$$, and $$$S_b$$$, but Watson does not know which transformations were applied.
Because Watson only sees digit counts:
Two writings are indistinguishable if one can be obtained from the other by applying some allowed sequence of cipher wheel operations (and then shuffling).
Your task is to compute how many different secrets Holmes can encode so that Watson can always decode them correctly.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases.
Each test case contains one line with:
The strings satisfy:
For each test case, output one integer — the maximum number of different secrets Holmes can encode.
It is guaranteed that the answer fits in a signed 64-bit integer.
33 1 03 19 053 1379 0123456789
285 79 13
In the first test case, only the identity transformation is possible, so all non-empty digit multisets of size at most $$$3$$$ are distinguishable.
In the last test case, the full affine group acts on the digits, so many different writings become indistinguishable, and the number of secrets is much smaller.
| Name |
|---|


