logo AlgoBeat OnlineJudge
登录 注册

#215516. [USACO26FEB] Strange Function B

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

For all positive integers , the function is defined as follows:

If has any digits that aren't or , for each digit of , set it to if it is odd or otherwise, and return . Otherwise, return .

Given a value of (), find how many times needs to be applied to until reaches . As this number might be very large, output its remainder when divided by .

输入格式

The first line contains (), the number of independent tests.

The next lines each contain a positive integer 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 .

输出格式

For each test case, output the remainder of the number of times when divided by on a separate line.

样例

样例输入 1

2
24680
210

样例输出 1

1
4

样例输入 2

1
1234567890123456789012345678901234567890

样例输出 2

511620083

数据范围与提示

Sample 1 Explanation

First test: becomes zero after one operation.

Second test:

SCORING:

  • Inputs 3-5: ,
  • Inputs 6-7:
  • Inputs 8-9:
  • Inputs 10-12: No additional constraints.

Problem credits: Aiden Bai