A drunkard is walking down the lanes of FooLand city at midnight and his steps are such that he moves A units forward in one step and B units backward in next step and this goes on. His house is at (N, 0) and his current position is (0, 0). Can you help him in finding out how many steps he would need to take to reach his house?
Print -1 if it is not possible for him to reach his house. Don’t take into account any movement in the y-direction. Note that distance between (i, 0) and (i+1, 0) is 1 unit and NOT 1 step.
The first line contains a single integer T denoting the number of test cases. Next T lines follow each of which contains three integers N, A, B according to the problem.
For each test case print in new line the number of steps he would need to take to reach his house.
1<= T <= 10^5
1 <= N <= 10^6
1 <= A, B <= 10^5
11 5 2
10 3 3
7 5 2
For 1st case: He will be at (5, 0) after step 1, at (3, 0) after step 2, at (8, 0) after step 3, at (6, 0) after step 4 and at (11, 0) after completing step 5. Hence, he would need 5 steps to reach his house.
For 2nd case: He will be at (3, 0) after step 1, at (0, 0) after step 2, at (3, 3) again after step 3 and this would go on. So, he would never reach his house.
For 3rd case: He will be at (5, 0) after step 1, at (3, 0) after step 2. In the next step, he can move 5 units forward but he requires to move only 4 units forward as his house is at (7, 0). So, he will move 4 units (instead of 5) and would stop there as his aim is only to reach his house. Hence, the answer is 3 steps.
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.