#P1374A. Required Remainder
Required Remainder
No submission language available for this problem.
Description
You are given three integers and . Your task is to find the maximum integer such that that , where is modulo operation. Many programming languages use percent operator % to implement it.
In other words, with given and you need to find the maximum possible integer from to that has the remainder modulo .
You have to answer independent test cases. It is guaranteed that such exists for each test case.
The first line of the input contains one integer () — the number of test cases. The next lines contain test cases.
The only line of the test case contains three integers and ().
It can be shown that such always exists under the given constraints.
For each test case, print the answer — maximum non-negative integer such that and . It is guaranteed that the answer always exists.
Input
The first line of the input contains one integer () — the number of test cases. The next lines contain test cases.
The only line of the test case contains three integers and ().
It can be shown that such always exists under the given constraints.
Output
For each test case, print the answer — maximum non-negative integer such that and . It is guaranteed that the answer always exists.
Samples
Note
In the first test case of the example, the answer is (thus, ). It is obvious that there is no greater integer not exceeding which has the remainder modulo .