Kids and Integers

시간 제한1초메모리 제한2048 MB

요약
N 이하의 양의 정수 중 각 자리 숫자의 합을 k번 반복 적용한 값이 m이 되는 수의 개수를 10^9+7로 나눈 나머지를 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 조합론, 수학, 정수론
정답자
아직 제출이 없습니다

문제

This is the fourth time that Little I and Little J have played the counting game, so they have decided not to create lengthy problem statements anymore. You only need to know that they have come up with another strange rule for selecting the numbers to count, and want to figure out how many such numbers are there.

For any positive integer nn, we define the function f(n)f(n) as the sum of its decimal digits, for example, f(114514)=1+1+4+5+1+4=16f(114514) = 1 + 1 + 4 + 5 + 1 + 4 = 16. Obviously, f(n)f(n) is also a positive integer, so the function can be applied repeatedly as f(f(n))f(f(n)), f(f(f(n)))f(f(f(n))), and so on. For positive integers nn and kk, we define the function g(n,k)g(n, k) as f(f(…f(n)…))f(f(\ldots f(n)\ldots)) with kk applications of ff.

To make the counting game different each time, the kids decided to set two positive integers kk and mm for each round, and then to specify the rule: in this round, the numbers to count are all positive integers nn satisfying g(n,k)=mg(n, k) = m.

As both of them are game experts, they can find arbitrarily many such integers. To prevent the game from going on forever, they also pick a positive integer NN in each round as the upper bound for counting. They want to know: among positive integers not exceeding NN, how many numbers satisfy g(n,k)=mg(n, k) = m? Since the answer may be very large, find it modulo 109+710^9 + 7.

입력

The first line of the input contains one integer TT, representing the number of rounds Little I and Little J will play (1≤T≤51 \le T \le 5).

Each of the next TT lines contains three positive integers NN, kk, mm describing a single round of the game (1≤N≤1010001 \le N \le 10^{1000}, 1≤k,m≤1091 \le k, m \le 10^9).

출력

For each of the TT rounds, print a line with a single integer: the number of numbers that cannot be counted in this round of the game, modulo 109+710^9 + 7.

예제1

  1. 예제 1

    입력
    2
    114 1 5
    514 2 10
    
    예상 출력
    8
    10