#abc290d. [abc290_d]Marking

[abc290_d]Marking

Problem Statement

There are NN squares indexed 00 through (N1)(N-1) arranged in a line. Snuke is going to mark every square by the following procedure.

  1. Mark square 00.
  2. Repeat the following steps i - iii (N1)(N-1) times.
    1. Initialize a variable xx with (A+D)bmodN(A+D) \\bmod N, where AA is the index of the square marked last time.
    2. While square xx is marked, repeat replacing xx with (x+1)bmodN(x+1) \\bmod N.
    3. Mark square xx.

Find the index of the square that Snuke marks for the KK-th time.

Given TT test cases, find the answer for each of them.

Constraints

  • 1leqTleq1051\\leq T \\leq 10^5
  • 1leqKleqNleq1091\\leq K\\leq N \\leq 10^9
  • 1leqDleq1091\\leq D \\leq 10^9
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format, where mathrmtesti\\mathrm{test}_i denotes the ii-th test case:

TT mathrmtest1\\mathrm{test}_1 mathrmtest2\\mathrm{test}_2 vdots\\vdots mathrmtestT\\mathrm{test}_T

Each test case is given in the following format:

NN DD KK

Output

Print TT lines.

The ii-th (1leqileqT)(1\\leq i \\leq T) line should contain the answer to the ii-th test case.


Sample Input 1

9
4 2 1
4 2 2
4 2 3
4 2 4
5 8 1
5 8 2
5 8 3
5 8 4
5 8 5

Sample Output 1

0
2
1
3
0
3
1
4
2

If N=4N=4 and D=2D=2, Snuke marks the squares as follows.

  1. Mark square 00.
  2. (11-st iteration) Let x=(0+2)bmod4=2x=(0+2)\\bmod 4=2. Since square 22 is not marked, mark it.
    (22-nd iteration) Let x=(2+2)bmod4=0x=(2+2)\\bmod 4=0. Since square 00 is marked, let x=(0+1)bmod4=1x=(0+1)\\bmod 4=1. Since square 11 is not marked, mark it.
    (33-rd iteration) Let x=(1+2)bmod4=3x=(1+2)\\bmod 4=3. Since square 33 is not marked, mark it.