Lottery Tickets

No attempts yetTime limit1sMemory limit128 MB

Problem

Hyunwoo decided to sell the tickets for this concert tour like lottery tickets. The rule is simple. A fan buys a ticket online and receives a unique reservation number. Numbers are assigned separately for each show, starting at 0 in the order the reservations arrive. A fan whose ticket wins gets into the concert, and a fan whose ticket loses does not.

Hyunwoo draws the winning number at random, but his random number generator is very slow. To call it as few times as possible he came up with a strange yet fair way of drawing the winners.

Once the reservations for a show close, Hyunwoo sets MM to the number of reservations and draws one random integer ZZ from {0,,M1}\{0, \dots, M-1\}. That is the only call to the generator. He then picks an integer r>0r > 0 that decides how hard it is to win.

Here is how ZZ and rr single out the winning tickets.

First, write the reservation numbers 0,,M10, \dots, M-1 and ZZ as decimal strings of length nn, where nn is the number of digits of M1M-1 written without leading zeros. A number with fewer than nn digits is padded with leading zeros so that every string has length nn.

Let reservation number AA be a1ana_1 \dots a_n and let ZZ be z1znz_1 \dots z_n. Ticket AA wins if the two strings share a common substring of length at least rr starting at the same position, that is, if there is an ii with 1inr+11 \le i \le n-r+1 and zizi+r1=aiai+r1z_i \dots z_{i+r-1} = a_i \dots a_{i+r-1}. For example, when Z=56743Z = 56743 and r=3r = 3, ticket 0674006740 wins while ticket 5614356143 does not.

Given MM, ZZ and rr, write a program that counts the winning tickets.

Input

The first line contains the number of shows CC. (1C50001 \le C \le 5000)

Each of the next CC lines contains MM, ZZ and rr for one show, separated by spaces. (0<M10180 < M \le 10^{18}, 0ZM10 \le Z \le M-1, r1r \ge 1) The value of rr never exceeds the number of digits of M1M-1.

Output

For each show, print the number of winning tickets on its own line.