#5440. Problem 2. Strange Function

0

Problem 2. Strange Function

Problem 2. Strange Function

USACO 2026 Third Contest, Bronze

For all positive integers xx, the function f(x)f(x) is defined as follows:

  • If xx has any digits that aren't 00 or 11, for each digit of xx, set it to 11 if it is odd or 00 otherwise, and return xx.
  • Otherwise, return x1x-1.

Given a value of xx (1x<1021051 \leq x < 10^{2\cdot 10^5}), find how many times ff needs to be applied to xx until xx reaches 00. As this number might be very large, output its remainder when divided by 109+710^9+7.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains TT (1T1051\le T\le 10^5), the number of independent tests.

The next TT lines each contain a positive integer xx consisting solely of the digits 0-9, with no leading zeros.

It is guaranteed that the total number of digits in all input integers does not exceed 10610^6.

OUTPUT FORMAT (print output to the terminal / stdout):

For each test case, output the remainder of the number of times when divided by 109+710^9+7 on a separate line.

SAMPLE INPUT:


2
24680
210

SAMPLE OUTPUT:


1
4

First test: xx becomes zero after one operation.

Second test: f(x)=10,f2(x)=9,f3(x)=1,f4(x)=0f(x)=10, f^2(x)=9, f^3(x)=1, f^4(x)=0

SAMPLE INPUT:


1
1234567890123456789012345678901234567890

SAMPLE OUTPUT:


511620083

SCORING: Inputs 3-5: T2000T\le 2000, x<109x< 10^{9}Inputs 6-7: x<1018x<10^{18}Inputs 8-9: x<1060x<10^{60}Inputs 10-12: No additional constraints.

Problem credits: Aidan Bai