#Lutece0020. Ticket Draw

Ticket Draw

Migrated from Lutece 20 Ticket Draw

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

The concert promoters of the Bon Jovi Tour 20132013 have decided to sell tickets for the concerts in lotteries. The rules are quite simple. For every concert, fans can apply online for tickets. In response they receive unique reservation numbers. It is important that for each concert the numbers distributed online are consecutive nonnegative integers starting with 00. Unfortunately, as the organizers tried to draw reservation numbers randomly, they discovered that the pseudo random generator they used is extremely slow. To minimize the number of calls to the generator, they invented a peculiar but fair enough way to distribute tickets.

As soon as the reservation for a concert is finished, the organizers ascertain the number of submissions MM and draw one random integer ZZ from {0,,M10,\cdots ,M−1} (remember, fans get integers from 00 to M1M−1). Integer ZZ is the only object the organizers have to draw randomly! Finally, to complete the selection rules the organizers determine an integer r>0r > 0 which has a direct impact on the number of selected tickets.

Now, using ZZ and rr, tickets are selected deterministically as follows. For the reservation numbers 0,,M10,\cdots ,M −1 and the number ZZ, their decimal representations of length nn are considered, where nn is the length of the representation of M1M − 1 without leading zeros. Thus, the decimal representations of the remaining numbers are padded on the left with leading zeros, if needed. If z1znz_1 \cdots z_n denotes such a representation for ZZ, then the holder of a number a1ana_1 \cdots a_n gets the ticket if and only if the strings z1znz_1 \cdots z_n and a1ana_1 \cdots a_n have a common contiguous substring of length rr or more which starts at the same position. Speaking formally, he or she gets the ticket if there exists an index ii, with 1inr+11\leq i\leq n − r + 1, such that zizi+r1=aiai+r1z_i \cdots z_{i+r−1} = a_i \cdots a_{i+r−1}. For example, if Z=56743Z = 56743 and r=3r = 3 then a fan with a reservation number 0674006740 gets a ticket, but a fan having 5614356143 does not.

Your task is to help the organizers to estimate, for given numbers MM, ZZ and rr, the exact number of tickets selected in such a way.

Input

The first line contains the number of concerts CC, with 1C50001\leq C\leq 5000. Then follow CC lines, each containing three integers MM, ZZ, and rr, with 0<M10180 < M\leq 10^{18}, 0ZM10\leq Z\leq M − 1 and r1r\geq 1. You may safely assume that rr is smaller or equal to the length of the decimal representation of M1M − 1.

Output

For each concert, print one line containing the number of tickets selected during the ticket draw.

Samples

输入数据 1

8
89 32 1
67 49 1
67 45 2
1000 23 1
1000 401 2
1000 54 2
3571 2 3
3571 976 3

输出数据 1

18
15
1
271
19
19
13
12

Resources

GCPC 2013