BETA

Difficulty Level: Easy

Submissions: 242 Accuracy:

26.45%

The Drunkard
     

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.


Input:
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.
 

Output:
For each test case print in new line the number of steps he would need to take to reach his house.

 

Constraints:
1<= T <= 10^5
1 <= N <= 10^6
1 <= A, B <= 10^5

 

Example:
Input:
3
11 5 2
10 3 3
7 5 2

Output:
5
-1
3

Explanation:
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.

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

Contributor: Sajal Agrawal

Set Default Code

					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

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