logo AlgoBeat OnlineJudge
登录 注册

#217139. [ICPC 2017 Urumqi R] Count Numbers

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

题目描述

Now Alice wants to sum up all integers whose digit sum is exactly .

However we all know the number of this kind of integers are unlimited. So she decides to sum up all these numbers

whose each digit is non-zero.

Since the answer could be large, she only needs the remainder when the answer divided by a given integer .

输入格式

The input has several test cases and the first line contains the integer which is the number of test cases.

For each test case, a line consisting of three integers and describes the restriction of the digit sum and the given integer .

输出格式

For each test case, output a line with the required answer.

Here we provide an explanation of the following sample output. All integers satisfying the restriction in the input are and . The sum of them all is and that is exactly the sample output.

样例

样例输入 1

5
2 1 1000000
3 1 1000000
2 2 1000000
3 3 1000000
10 1 1000000

样例输出 1

13
147
1625
877377
935943