Googlements (Large)

Count how many googlement strings could have decayed, through zero or more steps, into a given observed googlement.

Medium6GraphDFSMathBrute forceNo attempts yetTime limit5sMemory limit512 MB

Problem

A googlement of length LL is a string of LL decimal digits, each between 0 and LL inclusive, that contains at least one digit greater than 0. Leading zeroes are allowed. For example, 103 and 001 are valid googlements of length 3. 400 is not valid, because the digit 4 is greater than the length 3, and 000 is not valid, because it has no digit greater than 0.

A valid googlement can appear in the world at any time, and it later decays into another googlement by a fixed rule. For a googlement of length LL, count the 1s and write that number down, then count the 2s and write that number to the right of the previous one, and continue in the same way up to the count of LLs. The string written this way is the googlement after the decay, and its length is still LL. Some googlements decay into themselves.

For example, suppose 0414 has just appeared. It has one 1, zero 2s, zero 3s and two 4s, so it decays into 1002. That one has one 1, one 2, zero 3s and zero 4s, so it decays into 1100. Then 1100 decays into 2000, 2000 decays into 0100, 0100 decays into 1000, and 1000 decays into itself from then on.

You have observed a googlement GG. It might have just appeared, or it might be the result of one or more decay steps. Count the googlements that GG could have been when it first appeared in the world.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains one string GG describing a googlement.

Constraints

  • 1T1001 \le T \le 100
  • The length of GG is between 1 and 9, inclusive.
  • Each digit of GG is between 0 and the length of GG, inclusive.
  • GG contains at least one non-zero digit.

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting from 1 and yy is the number of googlements the observed one could have been when it first appeared.

Note

In the sample, the first googlement 20 could have been 20 from the start, or it could have decayed from 11. In turn, 11 could have decayed from 12 or from 21, and nothing decays into 12 or 21. That gives four possibilities.

The second googlement 1 is the only googlement of length 1, so the answer is 1.

Nothing decays into the third googlement 123, so 123 itself is the only possibility.