Exact Number of Drops
- Hmm... I asked for 400 drops, but there are 402 here.
- 400 drops, we never make mistakes.
Russian cartoon _The Mystery of the Third Planet
Do you think that managing a restaurant is easy? That is not the case when all clients are pretty demanding.
You are managing a restaurant, and every day a lot of people come and ask you to give them some drinks. As your restaurant has just recently opened, you don't have any vessels except two, which can accommodate a drops of liquid and b drops of liquid, respectively. In order not to make your clients wait (or at least to minimize their waiting time), you always have to determine the minimal number of steps required to obtain exactly c drops of liquid in one of the vessels.
At the beginning both vessels are empty. The following operations are counted as steps:
emptying a vessel;
filling a vessel;
pouring liquid from one vessel to the other (without spilling) until one of the vessels is either full or empty.
Eventually you became tired to do it all by hand and decided to write a program which will help you calculate the minimum number of steps required in all these cases.
Input
The first line contains the number of test cases T (1 ≤ T ≤ 10^5). Each of the next T lines contains one testcase and consists of three integers a, b and c (1 ≤ a, b, c ≤ 10^9).
Output
For each test case print the minimum number of steps required to obtain exactly c drops of liquid in one of the vessels or -1 if this is impossible.