Minimum Forbidden Jumps
Time Limit: 1 seconds
Memory Limit: 32 MB
A robot starts at gate
In one move, it can advance by an integer distance
$1 \le a \le m$ -
$a$ is not divisible by$k$ (i.e.,$a \not\equiv 0 \pmod{k}$ )
For each test case, determine the minimum number of moves required to land exactly on gate
It is guaranteed that reaching
Input Format:-
The first line contains an integer
Each of the next
Output Format:-
For each test case, print one integer — the minimum number of moves needed to reach exactly
Constraints:-
$1 \le t \le 1000$ $1 \le x \le 10^{18}$ $2 \le k \le 10^9$ -
$1 \le m \le 10^9$ Examples:- - Input:
1
7 7 8
- Output:
2
- Input:
1
60 2 3
- Output:
20
Note:-
In the first example,
In the first example,