atcoder#ARC158A. [ARC158A] +3 +5 +7

[ARC158A] +3 +5 +7

Score : 300300 points

Problem Statement

You are given integers x1x_1, x2x_2, and x3x_3. For these integers, you can perform the following operation any number of times, possibly zero.

  • Choose a permutation (i,j,k)(i,j,k) of (1,2,3)(1,2,3), that is, a triple of integers (i,j,k)(i,j,k) such that 1i,j,k31\leq i,j,k\leq 3 and ij,ik,jki\neq j, i\neq k, j\neq k.
  • Then, simultaneously replace xix_i with xi+3x_i+3, xjx_j with xj+5x_j+5, and xkx_k with xk+7x_k+7.

Your objective is to satisfy x1=x2=x3x_1=x_2=x_3. Determine whether it is achievable. If it is, print the minimum number of times you need to perform the operation to achieve it.

You have TT test cases to solve.

Constraints

  • 1T2×1051\leq T\leq 2\times 10^5
  • 1x1,x2,x31091\leq x_1, x_2, x_3 \leq 10^9

Input

The input is given from Standard Input in the following format:

TT

case1\text{case}_1

\vdots

caseT\text{case}_T

Each test case is in the following format:

x1x_1 x2x_2 x3x_3

Output

Print TT lines. The ii-th line should contain the following value for the ii-th test case.

  • The minimum number of times you need to perform the operation to satisfy x1=x2=x3x_1=x_2=x_3, if it is possible to satisfy this.
  • 1-1, otherwise.
4
2 8 8
1 1 1
5 5 10
10 100 1000
2
0
-1
315

For the first test case, you can do the following to satisfy x1=x2=x3x_1=x_2=x_3.

  • Perform the operation with (i,j,k)=(3,2,1)(i,j,k) = (3,2,1), replacing (x1,x2,x3)(x_1,x_2,x_3) with (9,13,11)(9,13,11).
  • Perform the operation with (i,j,k)=(2,3,1)(i,j,k) = (2,3,1), replacing (x1,x2,x3)(x_1,x_2,x_3) with (16,16,16)(16,16,16).