you are given three numbers a,b and c.write a program to determine the largest number that is less than or equal to c and leaves a reminder b when divided by a

constraints
1<=t<=1000
1<=a,b,c<=10^18

sample input

2
3 2 9
1 2 4

sample output

8
-1

Please suggest any approach to solve this question.
it was from todays hackwithinfy slot 2:30 to 5:30 and this test is cancelled too.

Your problem is not clear. Why the second output is -1? does the problem says that you should print -1 if there is no number like this? Please give the problem link!

First Observation is that if (b>=a), the answer will be -1. because a remainder can’t be greater than or equal to the divisor. Suppose our answer is x. Now, the qoutient for x can be a maximum of (c-b)/a. Now, just multiply the qoutient with a and then add the remainder to get the desired solution. Therefore, ans= a*((c-b)//a)+b