- Hmm... I asked for drops, but there are here.
- drops, we never make mistakes.
A classic space-themed cartoon
Do you think managing a restaurant is easy? That is not the case when all clients are quite demanding.
You are managing a restaurant, and every day many people come and ask you for drinks. As your restaurant has just recently opened, you have only two vessels, which can accommodate exactly drops of liquid and drops of liquid, respectively. In order not to make your clients wait (or at least to minimize their waiting time), you must determine the minimal number of steps required to obtain exactly 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 of doing this by hand and decided to write a program to help you calculate the minimum number of steps required in all such cases.
The first line contains the number of test cases (1 \le T \le 10^5). Each of the next lines contains one test case and consists of three integers , , and (1 \le a, b, c \le 10^9).
For each test case, print the minimum number of steps required to obtain exactly drops of liquid in one of the vessels, or if this is impossible.
Example 1