AT_arc222_f [ARC222F] Triple Transformation

Description

Consider an **operation** on a triple $ (x,y,z) $ of non-negative integers. In the operation, $ (x,y,z) $ is replaced according to the following rules: - If $ y+z

Input Format

The input is given from Standard Input in the following format: > $ T $ $ \mathrm{case}_1 $ $ \mathrm{case}_2 $ $ \vdots $ $ \mathrm{case}_T $ Each test case is given in the following format: > $ A_1 $ $ A_2 $ $ A_3 $ $ B_1 $ $ B_2 $ $ B_3 $

Output Format

Output one line per test case. For each test case, output the minimum number of operations required to obtain $ (B_1,B_2,B_3) $ by performing the operation on the triple $ (A_1,A_2,A_3) $ zero or more times. If it is impossible to obtain $ (B_1,B_2,B_3) $ no matter how many times the operation is performed, output `-1`.

Explanation/Hint

### Sample Explanation 1 For $ (A_1,A_2,A_3)=(2,3,4) $ , the triple changes as follows when the operation is repeatedly applied: - $ (2,3,4)\to (5,3,1)\to (1,6,2)\to (2,3,4)\to (5,3,1)\to (1,6,2)\to\cdots $ From this, we can see that the answers to the first three test cases are $ 0, 1, 2 $ . ### Constraints - $ 1\leq T\leq 300 $ - $ 0\leq A_1, A_2, A_3, B_1, B_2, B_3\leq 10^8 $ - All input values are integers.