パナソニックプログラミングコンテスト(AtCoder Beginner Contest 186)
E
Throne
AtCoder
⌀ 1461
原题
← DF →
翻译中…

Problem Statement

翻译中…

We have $N$ chairs arranged in a circle, one of which is a throne.

翻译中…

Takahashi is initially sitting on the chair that is $S$ chairs away from the throne in the clockwise direction. Now, he will repeat the move below.

翻译中…

Move: Go to the chair that is $K$ chairs away from the chair he is currently sitting on in the clockwise direction.

翻译中…

After how many moves will he be sitting on the throne for the first time? If he is never going to sit on it, report -1 instead.

翻译中…

You are asked to solve $T$ test cases.

翻译中…

Constraints

翻译中…
  • $1\leq T \leq 100$
  • $2\leq N \leq 10^9$
  • $1\leq S < N$
  • $1\leq K \leq 10^9$
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format. The first line is in the format below:

翻译中…

T

翻译中…

Then, the following $T$ lines represent $T$ test cases. Each of these lines is in the format below:

翻译中…

N S K

翻译中…

Output

翻译中…

For each test case, print the answer in its own line.

翻译中…

样例

Input #1
4
10 4 3
1000 11 2
998244353 897581057 595591169
10000 6 14
Output #1
2
-1
249561088
3571
In the first test case, we have $10$ chairs, and Takahashi is initially sitting on the chair that is $4$ chairs away from the throne in the clockwise direction. He will be sitting on the throne after $2$ moves of moving $3$ chairs in the clockwise direction. In the second test case, he will never sit on the throne, so we should print `-1`.
题目信息
题号
abc186_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。