Circular tour
Submissions: 293   Accuracy:

35.49%

  Difficulty: Easy   Marks: 2

Consider circular track with n points marked as 1, 2, …n. A person is initially placed on point k. The person moves m > 0, slot forward (in circular way) in each step. Find the minimum number of steps required so that the person reaches initial point k.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains integers n,k,m.

Output:
Print the minimum number of steps required so that the person reaches initial point k.

Constraints:
1<=T<=10^5
1<=n<=10^5
1<=m<=10^5
1<=k<=n

Example:
Input:

2
9 2 6
6 3 2

Output:
3
3

Explanation: In the first test case, Sequence of moves is 2 => 8 => 5 => 2.So total number of moves are 3.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Ayush Govil
Author: Ayush Govil 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.