This page is still under construction.

Parts of this page are still being built. What you see may change.

Long Number

Time limit1sMemory limit512 MB

Summary
Find the c-th digit of the number formed by concatenating the arithmetic sequence a, a+b, a+2b, ... with no separators.
Level

Medium5 of 10

Topics
Math, Binary search, Implementation, Prefix sum
Solved
No attempts yet

Problem

Albert has recently taken an interest in arithmetic sequences and is making several problems about them.

First, he picks arbitrary positive integers aa and bb and defines an arithmetic sequence xx: xi:=a+b×(i−1)x_i := a + b \times (i-1). That is, x1=ax_1 = a, x2=a+bx_2 = a+b, x3=a+b×2x_3 = a+b \times 2, and so on forever.

Without much thought, Albert kept writing x1,x2,x3,…x_1, x_2, x_3, \ldots one after another with no spaces (from left to right), and by doing so he created an extremely long number. In the middle of this, he became curious about what digit is written at position cc from the leftmost end.

For example, when a=1a = 1 and b=1b = 1, the long number Albert wrote is as follows (writing the first 21 terms of the arithmetic sequence): 123456789101112131415161718192021...

Here, the 15th digit from the left is 2 (the 2 of "12") and the 16th digit is 1 (the 1 of "13").

As another example, when a=3a = 3 and b=7b = 7, the long number is as follows (writing the first 11 terms of the arithmetic sequence): 310172431384552596673...

Here, the 15th digit from the left is 2 (the 2 of "52") and the 16th digit is 5 (the 5 of "59").

Given aa, bb, cc as input, find what the cc-th digit is when Albert writes the arithmetic sequence xi=a+b×(i−1)x_i = a + b \times (i-1) consecutively with no spaces.

Input

The first line gives the number of test cases TT.

Each test case is given on one line with aa, bb, cc separated by spaces.

Output

For each test case, output the answer on one line.

Constraints

  • 1≤T≤5,0001 \le T \le 5{,}000
  • 1≤a,b≤1061 \le a, b \le 10^6
  • 1≤c≤10121 \le c \le 10^{12}

Examples1

  1. Example 1

    Input
    8
    1 1 15
    1 1 16
    3 7 15
    3 7 16
    21 1 15
    21 1 16
    4 3 1000000000
    400 300 100000000
    
    Expected output
    2
    1
    2
    5
    2
    8
    4
    1