QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#7996. Numbering IV

统计

Background

This is the fourth time Little R and Little Z are playing the number-calling game, so they decided not to write a long problem statement. You only need to know that they have invented a strange rule for calling numbers and want to calculate which numbers can be called.

For any positive integer $n$, define the function $f(n)$ as the sum of the digits of $n$ in decimal representation. For example, $f(114514)=1+1+4+5+1+4=16$. Obviously, $f(n)$ is also a positive integer, so we can consider nested applications such as $f(f(n)), f(f(f(n)))$, and so on. Furthermore, for positive integers $n$ and $k$, we can define $g(n, k) = f(f(\dots f(n)))$ (with $k$ layers of $f$).

To ensure that the number-calling game is not the same every round, Little R and Little Z decide to set two positive integers $k$ and $m$ for each round, and stipulate that in this round, all positive integers $n$ satisfying $g(n, k) = m$ cannot be called.

Since both are experts at the game, to prevent the game from continuing indefinitely, each round provides a positive integer $N$ representing the upper bound for the numbers. They want to know: among all positive integers not exceeding $N$, how many cannot be called according to this rule?

Input

Read data from standard input.

The first line contains a positive integer $T$, representing the number of rounds of the game played by Little R and Little Z, with $1 \le T \le 5$.

The next $T$ lines each contain three positive integers $N, k, m$, describing a round of the game as defined above. It is guaranteed that $1 \le N \le 10^{1000}$ and $1 \le k, m \le 10^9$.

Output

Output to standard output.

Output $T$ lines, each containing an integer representing the number of integers that cannot be called in that round, modulo $10^9+7$.

Examples

Input 1

2
114 1 5
514 2 10

Output 1

8
10

Note

In the first round, the numbers that cannot be called are $5, 14, 23, 32, 41, 50, 104, 113$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.