The Buggy Robot
Submissions: 520   Accuracy:

33.86%

  Difficulty: Easy   Marks: 2

Ishaan recently made a robot which reduces him effort to move things. The robot moves from one place to another in a straight line to move things, but it has got a bug in it.
After moving N metres forward, it comes back M meters. Now Ishaan wants to know how much total distance does the robot cover if it needs to reach K metres from the starting point (Refer example for explanation). 
Help him find this. 
It is guranteed that the robot will reach its destination.

Input : 
First line of input contains a single integer T denoting the number of test cases.
The only line of each test case contains 3 space-separated integer N, M and K.

Output : 
For each test case, print the required answer in a new line.

Constraints : 
1 <= T <= 200
1 <= N,M <= 10^9
1 <= K <= 10^12

Example : 
Input : 

3
5 2 9
8 7 9
9 8 8
Output : 
17
23
8

Explanation : 
Case 1 :
 

Goes forward 5
Reaches 5
Distance = 5

Goes backward 2
Reaches 3
Distance = 7

Goes forward 5
Reaches 8
Distance = 12

Goes backward 2
Reaches 6
Distance = 14

Goes forward 3 (not 5 since it reaches the destination by travelling 3)
Reaches 9
Distance = 17

 

 

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

Author: goyalanubhav11


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.