Consider the following operations on a triple of integers. In one operation, you should:
- Choose an integer $d$ and an arithmetic operation ― either addition or multiplication.
- Choose a subset of elements of the triple.
- Apply the arithmetic operation to each of the chosen elements, i.e. either add $d$ to each of them or multiply each of them by $d$.
For example, if we have a triple $(3, 5, 7)$, we may choose to add $3$ to the first and third element, and we get $(6, 5, 10)$ using one operation.
You are given an initial triple $(p, q, r)$ and a target triple $(a, b, c)$. Find the minimum number of operations needed to transform $(p, q, r)$ into $(a, b, c)$.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains three space-separated integers $p$, $q$ and $r$.
- The second line contains three space-separated integers $a$, $b$ and $c$.

-----Output-----
For each test case, print a single line containing one integer ― the minimum required number of operations.

-----Constraints-----
- $1 \le T \le 1,000$
- $|p|, |q|, |r|, |a|, |b|, |c| \le 10^9$

-----Subtasks-----
Subtask #1 (10 points): $|p|, |q|, |r|, |a|, |b|, |c| \le 10$
Subtask #2 (90 points): original constraints

-----Example Input-----
2
3 5 7
6 5 10
8 6 3
9 7 8

-----Example Output-----
1
2

-----Explanation-----
Example case 1: We add $3$ to the first and third element of $(3, 5, 7)$ to form $(6, 5, 10)$.
Example case 2: We can add $1$ to each element to form $(9, 7, 4)$ and then multiply the third element by $2$.

Difficulty: interview

Starter code:

Solutions:
def eq_solve(v0, v1, u0, u1):
    den = u0 - v0
    num = u1 - v1
    if den != 0:
        return num / den
    return 1
 
def solve(p, q, r, a, b, c, rs):
    if p == a and q == b and r == c:
        return rs
    if rs >= 2:
        return 3
    res = 3
    adds = [a - p, b - q, c - r]
    muls = []
    if p != 0:
        muls.append(a / p)
    if q != 0:
        muls.append(b / q)
    if r != 0:
        muls.append(c / r)
    muls.append(eq_solve(p, a, q, b))
    muls.append(eq_solve(p, a, r, c))
    muls.append(eq_solve(q, b, r, c))
    msks = 2 ** 3
    for msk in range(msks):
        for add in adds:
            np = p
            nq = q
            nr = r
            if (msk & 1) > 0:
                np += add
            if (msk & 2) > 0:
                nq += add
            if (msk & 4) > 0:
                nr += add
            res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
        for mul in muls:
            np = p
            nq = q
            nr = r
            if (msk & 1) > 0:
                np *= mul
            if (msk & 2) > 0:
                nq *= mul
            if (msk & 4) > 0:
                nr *= mul
            res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
    return res
        
 
 
t = int(input())
 
while t > 0:
    p, q, r = map(int, input().split())
    a, b, c = map(int, input().split())
    z = solve(p, q, r, a, b, c, 0)
    print(z)
    t -= 1 

def eq_solve(v0, v1, u0, u1):
    den = u0 - v0
    num = u1 - v1
    if den != 0:
        return num / den
    return 1
 
def solve(p, q, r, a, b, c, rs):
    if p == a and q == b and r == c:
        return rs
    if rs >= 2:
        return 3
    res = 3
    adds = [a - p, b - q, c - r]
    muls = []
    if p != 0:
        muls.append(a / p)
    if q != 0:
        muls.append(b / q)
    if r != 0:
        muls.append(c / r)
    muls.append(eq_solve(p, a, q, b))
    muls.append(eq_solve(p, a, r, c))
    muls.append(eq_solve(q, b, r, c))
    msks = 7
    for msk in range(msks):
        msk = msk + 1
        for add in adds:
            np = p
            nq = q
            nr = r
            if (msk & 1) > 0:
                np += add
            if (msk & 2) > 0:
                nq += add
            if (msk & 4) > 0:
                nr += add
            res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
        for mul in muls:
            np = p
            nq = q
            nr = r
            if (msk & 1) > 0:
                np *= mul
            if (msk & 2) > 0:
                nq *= mul
            if (msk & 4) > 0:
                nr *= mul
            res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
    return res
        
 
 
t = int(input())
 
while t > 0:
    p, q, r = map(int, input().split())
    a, b, c = map(int, input().split())
    z = solve(p, q, r, a, b, c, 0)
    print(z)
    t -= 1 

def eqSolve(p, a, q, b) :
    x = p - q
    y = a - b
    if x != 0 :
        z = int(y/x)
        return z
    else :
        return 1
        
def solve(p, q, r, a, b, c, rs) :
    if p == a and q == b and r == c :
        return rs
    elif rs >= 2 :
        return 3
    else :
        res = 3
        m = 8
        adds = [a - p, b - q, c - r]
        muls = []
        if p != 0 :
            muls.append(a/p)
        if q != 0 :
            muls.append(b/q)
        if r != 0 :
            muls.append(c/r)
        muls.append(eqSolve(p, a, q, b))
        muls.append(eqSolve(p, a, r, c))
        muls.append(eqSolve(q, b, r, c))
        for n in range(m) :
            for add in adds :
                np = p
                nq = q
                nr = r
                if n & 1 > 0 :
                    np = np + add
                if n & 2 > 0 :
                    nq = nq + add
                if n & 4 > 0 :
                    nr = nr + add
                res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
            for mul in muls :
                np = p
                nq = q
                nr = r
                if n & 1 > 0 :
                    np = np*mul
                if n & 2 > 0 :
                    nq = nq*mul
                if n & 4 > 0 :
                    nr = nr*mul
                res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
        return res 

t = int(input())
x = 0
for x in range(t) :
    p, q, r = map(int, input().split())
    a, b, c = map(int, input().split())
    y = solve(p, q, r, a, b, c, 0)
    print(y)

def eqSolve(p, a, q, b) :
    x = p - q
    y = a - b
    if x != 0 :
        z = int(y/x)
        return z
    else :
        return 1
        
def solve(p, q, r, a, b, c, rs) :
    if p == a and q == b and r == c :
        return rs
    elif rs>=2 :
        return 3
    else :
        res = 3
        m = 7
        adds = [a - p, b - q, c - r]
        muls = []
        if p != 0 :
            muls.append(a/p)
        if q != 0 :
            muls.append(b/q)
        if r != 0 :
            muls.append(c/r)
        muls.append(eqSolve(p, a, q, b))
        muls.append(eqSolve(p, a, r, c))
        muls.append(eqSolve(q, b, r, c))
        for n in range(m) :
            n = n + 1
            for add in adds :
                np = p
                nq = q
                nr = r
                if n & 1 > 0 :
                    np = np + add
                if n & 2 > 0 :
                    nq = nq + add
                if n & 4 > 0 :
                    nr = nr + add
                res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
            for mul in muls :
                np = p
                nq = q
                nr = r
                if n & 1 > 0 :
                    np = np*mul
                if n & 2 > 0 :
                    nq = nq*mul
                if n & 4 > 0 :
                    nr = nr*mul
                res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
        return res 

t = int(input())
x = 0
for x in range(t) :
    p, q, r = map(int, input().split())
    a, b, c = map(int, input().split())
    y = solve(p, q, r, a, b, c, 0)
    print(y)

for _ in range(int(input())):
    a, b, c = map(int, input().split())
    p, q, r = map(int, input().split())
    zeros = [a, b, c].count(0)
    d, e, f = p - a, q - b, r - c
    operations = 0
    if d == e == f:
        if d:
            operations = 1
        else:
            operations = 0
    elif zeros >= 2:
        if (d == e and f == 0) or (d == e == 0 and f) or (e == f and d == 0) or (e == f == 0 and d) or (f == d and e == 0) or (f == d == 0 and e):
            operations = 1
        elif d == e or e == f or f == d or d == e + f or e == d + f or f == d + e:
            operations = 2
    elif zeros == 1:
        if a == 0:
            if (d == e and f == 0) or (d == e == 0 and f) or (e == f and d == 0) or (e == f == 0 and d) or (f == d and e == 0) or (f == d == 0 and e) or (d == 0 and q // b == r // c and q % b == 0 and r % c == 0):
                operations = 1
            elif d == e or e == f or f == d or (d and q // b == r // c and q % b == 0 and r % c == 0) or d == e + f or e == d + f or f == d + e:
                operations = 2
        elif b == 0:
            if (d == e and f == 0) or (d == e == 0 and f) or (e == f and d == 0) or (e == f == 0 and d) or (f == d and e == 0) or (f == d == 0 and e) or (e == 0 and p // a == r // c and p % a == 0 and r % c == 0):
                operations = 1
            elif d == e or e == f or f == d or (e and p // a == r // c and p % a == 0 and r % c == 0) or d == e + f or e == d + f or f == d + e:
                operations = 2
        else:
            if (d == e and f == 0) or (d == e == 0 and f) or (e == f and d == 0) or (e == f == 0 and d) or (f == d and e == 0) or (f == d == 0 and e) or (f == 0 and p // a == q // b and p % a == 0 and q % b == 0):
                operations = 1
            elif d == e or e == f or f == d or (f and p // a == q // b and p % a == 0 and q % b == 0) or d == e + f or e == d + f or f == d + e:
                operations = 2
    else:
        x, y, z = p // a, q // b, r // c
        if (d == e and f == 0) or (d == e == 0 and f) or (e == f and d == 0) or (e == f == 0 and d) or (f == d and e == 0) or (f == d == 0 and e) or (x == y == z and p % a == 0 and q % b == 0 and r % c == 0) or (d == 0 and y == z and q % b == 0 and r % c == 0) or (e == 0 and x == z and p % a == 0 and r % c == 0) or (f == 0 and x == y and p % a == 0 and q % b == 0):
            operations = 1
        elif d == e or e == f or f == d or (f and x == y and p % a == 0 and q % b == 0) or (d and y == z and q % b == 0 and r % c == 0) or (e and x == z and p % a == 0 and r % c == 0) or (d == 0 and e != f and e and f) or (e == 0 and d != f and d and f) or (f == 0 and d != e and d and e) or d == e + f or e == d + f or f == d + e or (p % a == 0 and q % b == 0 and r % c == 0 and (x * y == z or y * z == x or z * x == y)):
            operations = 2
    if operations == 0:
        if d:
            operations += 1
        if e:
            operations += 1
        if f:
            operations += 1
    if operations == 3:
        try:
            u, v, w = (q * a - p * b) // (p - q), (r * b - q * c) // (q - r), (p * c - r * a) // (r - p)
            if u == v == w and (q * a - p * b) % (p - q) == 0 and (r * b - q * c) % (q - r) == 0 and (p * c - r * a) % (r - p) == 0 and p // (a + u) == q // (b + u) == r // (c + u) and p % (a + u) == 0 and q % (b + u) == 0 and r % (c + u) == 0:
                operations = 2
        except:
            pass
        if operations == 3:
            try:
                x = p // a
                if p % a == 0 and ((q % x == 0 and c + (q // x) - b == r) or (r % x == 0 and b + (r // x) - c == q)):
                    operations = 2
            except:
                pass
            if operations == 3:
                try:
                    x = q // b
                    if q % b == 0 and ((p % x == 0 and c + (p // x) - a == r) or (r % x == 0 and a + (r // x) - c == p)):
                        operations = 2
                except:
                    pass
                if operations == 3:
                    try:
                        x = r // c
                        if r % c == 0 and ((p % x == 0 and b + (p // x) - a == q) or (q % x == 0 and a + (q // x) - b == p)):
                            operations = 2
                    except:
                        pass
                    if operations == 3:
                        try:
                            if (q * a - p * b) % (p - q) == 0:
                                u, x = (q * a - p * b) // (p - q), p // (a + u)
                                if x == q // (b + u) and p % (a + u) == 0 and q % (b + u) == 0 and (c * x == r or c + u == r):
                                    operations = 2
                        except:
                            pass
                        if operations == 3:
                            try:
                                if (r * b - q * c) % (q - r) == 0:
                                    v, x = (r * b - q * c) // (q - r), q // (b + v)
                                    if x == r // (c + v) and q % (b + v) == 0 and r % (c + v) == 0 and (a * x == p or a + v == p):
                                        operations = 2
                            except:
                                pass
                            if operations == 3:
                                try:
                                    if (p * c - r * a) % (r - p) == 0:
                                        w, x = (p * c - r * a) // (r - p), r // (c + w)
                                        if x == p // (a + w) and r % (c + w) == 0 and p % (a + w) == 0 and (b * x == q or b + w == q):
                                            operations = 2
                                except:
                                    pass
                                if operations == 3:
                                    try:
                                        x, y, z = (p - q) // (a - b), (q - r) // (b - c), (r - p) // (c - a)
                                        if x == y == z and (p - q) % (a - b) == 0 and (q - r) % (b - c) == 0 and (r - p) % (c - a) == 0 and p - a * x == q - b * y == r - c * z:
                                            operations = 2
                                    except:
                                        pass
                                    if operations == 3:
                                        try:
                                            x = p // a
                                            if p % a == 0 and (b * x + r - c == q or c * x + q - b == r):
                                                operations = 2
                                        except:
                                            pass
                                        if operations == 3:
                                            try:
                                                x = q // b
                                                if q % b == 0 and (a * x + r - c == p or c * x + p - a == r):
                                                    operations = 2
                                            except:
                                                pass
                                            if operations == 3:
                                                try:
                                                    x = r // c
                                                    if r % c == 0 and (a * x + q - b == p or b * x + p - a == q):
                                                        operations = 2
                                                except:
                                                    pass
                                                if operations == 3:
                                                    try:
                                                        x = (p - q) // (a - b)
                                                        if (p - q) % (a - b) == 0 and p - a * x == q - b * x and (c + p - a * x == r or c * x == r):
                                                            operations = 2
                                                    except:
                                                        pass
                                                    if operations == 3:
                                                        try:
                                                            y = (q - r) // (b - c)
                                                            if (q - r) % (b - c) == 0 and q - b * y == r - c * y and (a + q - b * y == p or a * y == p):
                                                                operations = 2
                                                        except:
                                                            pass
                                                        if operations == 3:
                                                            try:
                                                                z = (r - p) // (c - a)
                                                                if (r - p) % (c - a) == 0 and r - c * z == p - a * z and (b + r - c * z == q or b * z == q):
                                                                    operations = 2
                                                            except:
                                                                pass
    print(operations)

from sys import *
def eq_solve(v0, v1, u0, u1):
    den = u0 - v0
    num = u1 - v1
    if den != 0:
        return num / den
    return 1
 
def solve(p, q, r, a, b, c, rs):
    if p == a and q == b and r == c:
        return rs
    if rs >= 2:
        return 3
    res = 3
    adds = [a - p, b - q, c - r]
    muls = []
    if p != 0:
        muls.append(a / p)
    if q != 0:
        muls.append(b / q)
    if r != 0:
        muls.append(c / r)
    muls.append(eq_solve(p, a, q, b))
    muls.append(eq_solve(p, a, r, c))
    muls.append(eq_solve(q, b, r, c))
    msks = 2 ** 3
    for msk in range(msks):
        for add in adds:
            np = p
            nq = q
            nr = r
            if (msk & 1) > 0:
                np += add
            if (msk & 2) > 0:
                nq += add
            if (msk & 4) > 0:
                nr += add
            res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
        for mul in muls:
            np = p
            nq = q
            nr = r
            if (msk & 1) > 0:
                np *= mul
            if (msk & 2) > 0:
                nq *= mul
            if (msk & 4) > 0:
                nr *= mul
            res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
    return res
        
t = int(stdin.readline())
while t > 0:
    p,q,r = map(int,stdin.readline().split())
    a,b,c = map(int,stdin.readline().split())
    print(solve(p,q,r,a,b,c,0))
    t -= 1

def eq_solve(v0, v1, u0, u1):
    den = u0 - v0
    num = u1 - v1
    if den != 0:
        return num / den
    return 1
 
def solve(p, q, r, a, b, c, rs):
    if p == a and q == b and r == c:
        return rs
    if rs >= 2:
        return 3
    res = 3
    adds = [a - p, b - q, c - r]
    muls = []
    if p != 0:
        muls.append(a / p)
    if q != 0:
        muls.append(b / q)
    if r != 0:
        muls.append(c / r)
    muls.append(eq_solve(p, a, q, b))
    muls.append(eq_solve(p, a, r, c))
    muls.append(eq_solve(q, b, r, c))
    msks = 2 ** 3
    for msk in range(msks):
        for add in adds:
            np = p
            nq = q
            nr = r
            if (msk & 1) > 0:
                np += add
            if (msk & 2) > 0:
                nq += add
            if (msk & 4) > 0:
                nr += add
            res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
        for mul in muls:
            np = p
            nq = q
            nr = r
            if (msk & 1) > 0:
                np *= mul
            if (msk & 2) > 0:
                nq *= mul
            if (msk & 4) > 0:
                nr *= mul
            res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
    return res
        
 
 
t = int(input())
 
while t > 0:
    p, q, r = map(int, input().split())
    a, b, c = map(int, input().split())
    print(solve(p, q, r, a, b, c, 0))
    t -= 1 

import sys
def fop(s,end='\n'): sys.stdout.write(str(s)+end)
def fip(): return sys.stdin.readline().strip()
fintinp = lambda : int(fip()) 
def flistinp(func= int): return list(map(func,fip().split())) 
def fnsepline(n,func=str): return [func(fip()) for _ in range(n)]
from functools import lru_cache
#-------------------code------------------------
@lru_cache(maxsize=1<<10)
def byeqs(pqr, abc):
    # f_ans = 3
    p,q,r = pqr
    a,b,c = abc
    # zeq = a*(r-q) + b*(p-r) + c*(q-p)
    # m=n=None # for y = mx + n
    muls = [] 
    # if zeq==0:
    try:
        if p!=q:
            m_ = (a-b)//(p-q)
            muls.append(m_)
    except: pass
    try:
        if p!=r:
            m_ = (a-c)//(p-r)
            muls.append(m_)
    except: pass
    try:
        if q!=r:
            m_ = (b-c)//(q-r)
            muls.append(m_)
    except: pass
    return muls

@lru_cache(maxsize=1<<10)
def recSolver(pqr, abc, ans = 0):
    if pqr == abc: return ans 
    if ans>=2: return 3
    adds = [abc[i]-pqr[i] for i in range(3)]
    muls = [abc[i]//pqr[i] if pqr[i]!=0 else 0 for i in range(3)] + byeqs(pqr, abc)
    f_ans = 3 
    for ss in range(8):
        for a in adds:
            pqr_copy = list(pqr)
            for i in [1,2,4]:
                if ss&i:
                    pqr_copy[i>>1]+=a 
            f_ans = min(f_ans, recSolver(tuple(pqr_copy), tuple(abc), ans+1))
            
        for m in muls:
            pqr_copy = list(pqr)
            for i in [1,2,4]:
                if ss&i:
                    pqr_copy[i>>1]*=m 
            f_ans = min(f_ans, recSolver(tuple(pqr_copy), tuple(abc), ans+1))
    return f_ans
                
for _ in range(fintinp()):
    pqr = flistinp()
    abc = flistinp()
    fop(recSolver(tuple(pqr), tuple(abc), 0))

import sys
def fop(s,end='\n'): sys.stdout.write(str(s)+end)
def fip(): return sys.stdin.readline().strip()
fintinp = lambda : int(fip()) 
def flistinp(func= int): return list(map(func,fip().split())) 
def fnsepline(n,func=str): return [func(fip()) for _ in range(n)]
from functools import lru_cache
#-------------------code------------------------
@lru_cache(maxsize=1<<20)
def byeqs(pqr, abc):
    # f_ans = 3
    p,q,r = pqr
    a,b,c = abc
    # zeq = a*(r-q) + b*(p-r) + c*(q-p)
    # m=n=None # for y = mx + n
    muls = [] 
    # if zeq==0:
    try:
        if p!=q:
            m_ = (a-b)//(p-q)
            muls.append(m_)
    except: pass
    try:
        if p!=r:
            m_ = (a-c)//(p-r)
            muls.append(m_)
    except: pass
    try:
        if q!=r:
            m_ = (b-c)//(q-r)
            muls.append(m_)
    except: pass
    return muls

@lru_cache(maxsize=1<<20)
def recSolver(pqr, abc, ans = 0):
    if pqr == abc: return ans 
    if ans>=2: return 3
    adds = [abc[i]-pqr[i] for i in range(3)]
    muls = [abc[i]//pqr[i] if pqr[i]!=0 else 0 for i in range(3)] + byeqs(pqr, abc)
    f_ans = 3 
    for ss in range(8):
        for a in adds:
            pqr_copy = list(pqr)
            for i in [1,2,4]:
                if ss&i:
                    pqr_copy[i>>1]+=a 
            f_ans = min(f_ans, recSolver(tuple(pqr_copy), tuple(abc), ans+1))
            
        for m in muls:
            pqr_copy = list(pqr)
            for i in [1,2,4]:
                if ss&i:
                    pqr_copy[i>>1]*=m 
            f_ans = min(f_ans, recSolver(tuple(pqr_copy), tuple(abc), ans+1))
    return f_ans
                
for _ in range(fintinp()):
    pqr = flistinp()
    abc = flistinp()
    fop(recSolver(tuple(pqr), tuple(abc), 0))

import sys
def fop(s,end='\n'): sys.stdout.write(str(s)+end)
def fip(): return sys.stdin.readline().strip()
fintinp = lambda : int(fip()) 
def flistinp(func= int): return list(map(func,fip().split())) 
def fnsepline(n,func=str): return [func(fip()) for _ in range(n)]
#-------------------code------------------------
def byeqs(pqr, abc):
    # f_ans = 3
    p,q,r = pqr
    a,b,c = abc
    # zeq = a*(r-q) + b*(p-r) + c*(q-p)
    # m=n=None # for y = mx + n
    muls = [] 
    # if zeq==0:
    try:
        if p!=q:
            m_ = (a-b)//(p-q)
            muls.append(m_)
    except: pass
    try:
        if p!=r:
            m_ = (a-c)//(p-r)
            muls.append(m_)
    except: pass
    try:
        if q!=r:
            m_ = (b-c)//(q-r)
            muls.append(m_)
    except: pass
    return muls

def recSolver(pqr, abc, ans = 0):
    if pqr == abc: return ans 
    if ans>=2: return 3
    adds = [abc[i]-pqr[i] for i in range(3)]
    muls = [abc[i]//pqr[i] if pqr[i]!=0 else 0 for i in range(3)] + byeqs(pqr, abc)
    f_ans = 3 
    for ss in range(8):
        for a in adds:
            pqr_copy = list(pqr)
            for i in [1,2,4]:
                if ss&i:
                    pqr_copy[i>>1]+=a 
            f_ans = min(f_ans, recSolver(pqr_copy, abc, ans+1))
            
        for m in muls:
            pqr_copy = list(pqr)
            for i in [1,2,4]:
                if ss&i:
                    pqr_copy[i>>1]*=m 
            f_ans = min(f_ans, recSolver(pqr_copy, abc, ans+1))
    return f_ans
                
for _ in range(fintinp()):
    pqr = flistinp()
    abc = flistinp()
    fop(recSolver(pqr, abc, 0))

T = int(input())
for tc in range(T):
    p, q, r = map(int, input().split())
    a ,b, c = map(int, input().split())
    p_diff = a - p
    q_diff = b - q
    r_diff = c - r
    flag = 0
    
    # GCD of Three Numbers
    def gcd(a,b):
        if b == 0:
            return a
        else:
            return gcd(b, a%b)

    g_c_d = gcd(a,gcd(b,c))
    
    def factors(x):
        # We will store all factors in `result`
        result = []
        i = 2
        # This will loop from 1 to int(sqrt(x))
        while i*i <= x:
            # Check if i divides x without leaving a remainder
            if x % i == 0:
                result.append(i)
                # Handle the case explained in the 4th
                if x//i != i: # In Python, // operator performs integer/floored division
                    result.append(x//i)
            i += 1
        # Return the list of factors of x
        return result
    listi = factors(g_c_d)
    
    try:
        p_rem = a / p
    except:
        p_rem = 1
    try:
        q_rem = b / q
    except:
        q_rem = 1
    try:
        r_rem = c / r
    except:
        r_rem = 1
    
    if a == p and b == q and c == r:
        print("0")
        flag = 1
        continue
    elif p_rem == q_rem == r_rem != 1:
        print("1")
        flag = 1
        continue
    elif p_diff == q_diff == r_diff:
        print("1")
        flag = 1
        continue
    elif p == a and q == b:
        print("1")
        flag = 1
        continue
    elif p == a and r == c:
        print("1")
        flag = 1
        continue
    elif q == b and r == c:
        print("1")
        continue
    elif p == a:
        if q_diff == r_diff:
            print("1")
            flag = 1
            continue
        elif q_rem == r_rem != 1:
            print("1")
            flag = 1
            continue
        else:
            print("2")
            flag = 1
            continue
    elif q == b:
        if p_diff == r_diff:
            print("1")
            flag = 1
            continue
        elif p_rem == r_rem != 1:
            print("1")
            flag = 1
            continue
        else:
            print("2")
            flag = 1
            continue
    elif r == c:
        if q_diff == p_diff:
            print("1")
            flag = 1
        elif q_rem == p_rem != 1:
            print("1")
            flag = 1
            continue
        else:
            print("2")
            flag = 1
    elif p_diff == 0:
        if q_diff == r_diff:
            print("1")
            flag = 1
            continue
        elif q_rem == r_rem:
            print("1")
            flag = 1
            continue
        else:
            print("2")
            flag = 1
            continue
    elif q_diff == 0:
        if p_diff == r_diff:
            print("1")
            flag = 1
            continue
        elif p_rem == r_rem:
            print("1")
            flag = 1
            continue
        else:
            print("2")
            flag = 1
            continue
    elif r_diff == 0:
        if p_diff == q_diff:
            print("1")
            flag = 1
            continue
        elif p_rem == q_rem:
            print("1")
            flag = 1
            continue
        else:
            print("2")
            flag = 1
            continue
    elif r_diff - p_diff == q_diff:
        print("2")
        continue
    elif r_diff - q_diff == p_diff:
        print("2")
        continue
    elif q_diff - r_diff == p_diff:
        print("2")
        continue
    elif q_diff - p_diff == r_diff:
        print("2")
        continue
    elif p_diff - q_diff == r_diff:
        print("2")
        continue
    elif p_diff - r_diff == q_diff:
        print("2")
        continue
    
    elif p_diff == q_diff:
        print("2")
        flag = 1
        continue
    elif q_diff == r_diff:
        print("2")
        flag = 1
        continue
    elif p_diff == r_diff:
        print("2")
        flag = 1
        continue
    elif p_rem == q_rem and r_rem != 1:
        print("2")
        flag = 1
        continue
    elif p_rem == r_rem and q_rem != 1:
        print("2")
        flag = 1
        continue
    elif q_rem == r_rem and p_rem != 1:
        print("2")
        flag = 1
        continue
    elif ((a // g_c_d) - p) == ((b // g_c_d) - q) == ((c // g_c_d) - r):
        print("2")
        flag = 1
        continue
    if flag == 0:
        try:
            if (r_diff - b) / q == (r_diff - a) / p:
                print("2")
                flag = 1
                continue
        except:
            if (r_diff - b) / 1 == (r_diff - a) / 1:
                print("2")
                flag = 1
                continue
        try:
            if (q_diff - c) / r == (q_diff - a) / p:
                print("2")
                flag = 1
                continue
        except:
            if (q_diff - c) / 1 == (q_diff - a) / 1:
                print("2")
                flag = 1
                continue
        try:
            if (p_diff - c) / r == (p_diff - b) / q:
                print("2")
                flag = 1
                continue
        except:
            if (p_diff - c) / 1 == (p_diff - b) / 1:
                print("2")
                flag = 1
                continue
        try:
            if (b/ r_rem) - q == a - p:
                print("2")
                flag = 1
                continue
        except:
            if (b/ 1) - q == a - p:
                print("2")
                flag = 1
                continue
        try:    
            if (a / r_rem) - p == b - q:
                print("2")
                flag = 1
                continue
        except:
            if (a / 1) - p == b - q:
                print("2")
                flag = 1
                continue
        try:
            if (b / p_rem) - q == c - r:
                print("2")
                flag = 1
                continue
        except:
            if (b / 1) - q == c - r:
                print("2")
                flag = 1
                continue
        try:
            if (c / p_rem) - r == b - q:
                print("2")
                flag = 1
                continue
        except:
            if (c / 1) - r == b - q:
                print("2")
                flag = 1
                continue
        try:
            if (c / q_rem) - r == a - p:
                print("2")
                flag = 1
                continue
        except:
            if (c / 1) - r == a - p:
                print("2")
                flag = 1
                continue
        try:
            if (a / q_rem) - p == c - r:
                print("2")
                flag = 1
                continue
        except:
            if (a / 1) - p == c - r:
                print("2")
                flag = 1
                continue
            
    if flag == 0:
        try:
            if (b - (c-r)) / q == p_rem:
                print("2")
                flag = 1
                continue
        except:
            x = 1
            if (b - (c-r)) / x == p_rem:
                print("2")
                flag = 1
                continue
        try:
            if (b - (a-p)) / q == r_rem:
                print("2")
                flag = 1
                continue
        except:
            x = 1
            if (b - (a-p)) / x == r_rem:
                print("2")
                flag = 1
                continue
            
        try:
            if (a - (b-q)) / p == r_rem:
                print("2")
                flag = 1
                continue
        except:
            x = 1
            if (a - (b-q)) / x == r_rem:
                print("2")
                flag = 1
                continue
        try:
            if (a - (c-r)) / p == q_rem:
                print("2")
                flag = 1
                continue
            
        except:
            x = 1
            if (a - (c-r)) / x == q_rem:
                print("2")
                flag = 1
                continue
        try:
            if (c - (b-q)) / r == p_rem:
                print("2")
                flag = 1
                continue
        except:
            x = 1
            if (c - (b-q)) / x == p_rem:
                print("2")
                flag = 1
                continue
        try:
            if (c - (a-p)) / r == q_rem:
                print("2")
                flag = 1
                continue
        except:
            x = 1
            if (c - (a-p)) / x == q_rem:
                print("2")
                flag = 1
                continue
        try:
            if (b / r_rem) / q == p_rem:
                print("2")
                flag = 1
                continue
        except:
            x = 1
            if (b / x) / x == p_rem:
                print("2")
                flag = 1
                continue
        try:
            if (a / r_rem) / p == q_rem:
                print("2")
                flag = 1
                continue
        except:
            x = 1
            if (a / x) / x == q_rem:
                print("2")
                flag = 1
                continue
        try:
            if (b / p_rem) / q == r_rem:
                print("2")
                flag = 1
                continue
        except:
            x = 1
            if (b / x) / x == r_rem:
                print("2")
                flag = 1
                continue
        try:
            if (c / p_rem) / r == q_rem:
                print("2")
                flag = 1
                continue
        except:
            x = 1
            if (c / x) / x == q_rem:
                print("2")
                flag = 1
                continue
        try:
            if (a / q_rem) / p == r_rem:
                print("2")
                flag = 1
                continue
        except:
            x = 1
            if (a / x) / x == r_rem:
                print("2")
                flag = 1
                continue
        try:
            if (c / q_rem) / r == p_rem:
                print("2")
                flag = 1
                continue
        except:
            x = 1
            if (c / x) / x == p_rem:
                print("2")
                flag = 1
                continue
    
    if flag == 0:
        try:
            if b / (q + (c-r)) == a / (p +(c-r)):
                print("2")
                flag = 1
                continue
        except:
            rem1 = 1
            rem2 = 1
            if b / rem1 == a / rem2:
                print("2")
                flag = 1
                continue
            
        try:
            if c / (r + (b-q)) == a / (p +(b-q)):
                print("2")
                flag = 1
                continue
        except:
            rem1 = 1
            rem2 = 1
            if c / rem1 == a / rem2:
                print("2")
                flag = 1
                continue
            
        try:
            if b / (q + (a-p)) == c / (r +(a-p)):
                print("2")
                flag = 1
                continue
        except:
            rem1 = 1
            rem2 = 1
            if b / rem1 == c / rem2:
                print("2")
                flag = 1
                continue
            
    
    if flag == 0:
        if(p-q != 0):
            rem = (a-b)/(p-q)
            diff = a - (p*rem)
            if(rem%1 == 0 and diff%1 == 0 and (r*rem+diff)==c):
                print("2")
                flag = 1
    if flag == 0:
        if len(listi) > 0:
            for x in listi:
                if ((a // x) - p) == ((b // x) - q) == ((c // x) - r):
                    print("2")
                    flag = 1
    if flag == 0:
        if a - (q_rem * p) == c - (q_rem * r):
            print("2")
            flag = 1
            continue
        elif a - (r_rem * p) == b - (r_rem * q):
            print("2")
            flag = 1
            continue
        elif c - (p_rem * r) == b - (p_rem * q):
            print("2")
            flag = 1
            continue
    if flag == 0:
        print("3")

intput = lambda: [int(i) for i in input().split()]
# Write your code here
from sys import stdout
sol = "3332323313233322223333"
subsets = ['100', '010', '001', '110', '101', '011', '111']
eq = lambda x, y: abs(x - y) < 1e-6
def check(x):
    if x == [9, 7, 4]:
        print("Debug")
    if x == y:
        return 0
    d, q, f = [], [], []
    for i in range(3):
        d.append(y[i] - x[i])
        q.append(0.5 if x[i] == 0 else y[i] / x[i])
        f.append(q[i] % 1 == 0)
    for i in range(3):
        j, k = (i + 1) % 3, (i + 2) % 3
        if x[j] == y[j] and x[k] == y[k]:
            return 1
        if x[i] == y[i] and (d[j] == d[k] or (f[j] and eq(q[j], q[k]))):
            return 1
    if (d[0] == d[1] and d[0] == d[2]) or (f[0] and eq(q[0], q[1]) and eq(q[0], q[2])):
        return 1
    return 2
def move(subset, oper, d):
    res = x.copy()
    for i in range(3):
        if subset[i] == '1':
            res[i] = res[i] + d if oper else res[i] * d
    return res
for tc in range(int(input())):
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    a = check(x)
    if a < 2:
        print(a)
        continue
    d, q, f = [], [], []
    for i in range(3):
        d.append(y[i] - x[i])
        q.append(0.5 if x[i] == 0 else y[i] / x[i])
        f.append(q[i] % 1 == 0)
    flag = False
    for subset in subsets:
        for i in range(3):
            a = check(move(subset, True, d[i]))
            if a < 2:
                print(2)
                flag = True
                break
            if f[i]:
                a = check(move(subset, False, q[i]))
                if a < 2:
                    print(2)
                    flag = True
                    break
        if flag:
            break
    if flag:
        continue
    for i in range(3):
        j, k = (i + 1) % 3, (i + 2) % 3
        if x[j] != 0 and x[k] != 0 and eq((y[j] - d[i]) / x[j], (y[k] - d[i]) / x[k]) and ((y[j] - d[i]) / x[j]) % 1 == 0:
            print(2)
            flag = True
            break
    if flag:
        continue
    if x[0] != x[1] and x[0] != x[2] and eq((y[0] - y[1]) / (x[0] - x[1]), (y[0] - y[2]) / (x[0] - x[2])):
        print(2)
        continue
    print(3)

intput = lambda: [int(i) for i in input().split()]
# Write your code here
from sys import stdout
sol = "3332323313233322223333"
subsets = ['100', '010', '001', '110', '101', '011', '111']
eq = lambda x, y: abs(x - y) < 1e-6
def check(x):
    if x == [9, 7, 4]:
        print("Debug")
    if x == y:
        return 0
    d, q, f = [], [], []
    for i in range(3):
        d.append(y[i] - x[i])
        q.append(0.5 if x[i] == 0 else y[i] / x[i])
        f.append(q[i] % 1 == 0)
    for i in range(3):
        j, k = (i + 1) % 3, (i + 2) % 3
        if x[j] == y[j] and x[k] == y[k]:
            return 1
        if x[i] == y[i] and (d[j] == d[k] or (f[j] and eq(q[j], q[k]))):
            return 1
    if (d[0] == d[1] and d[0] == d[2]) or (f[0] and eq(q[0], q[1]) and eq(q[0], q[2])):
        return 1
    return 2
def move(subset, oper, d):
    res = x.copy()
    for i in range(3):
        if subset[i] == '1':
            res[i] = res[i] + d if oper else res[i] * d
    return res
for tc in range(int(input())):
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    a = check(x)
    if a < 2:
        print(a)
        continue
    d, q, f = [], [], []
    for i in range(3):
        d.append(y[i] - x[i])
        q.append(0.5 if x[i] == 0 else y[i] / x[i])
        f.append(q[i] % 1 == 0)
    flag = False
    for subset in subsets:
        for i in range(3):
            a = check(move(subset, True, d[i]))
            if a < 2:
                print(2)
                flag = True
                break
            if f[i]:
                a = check(move(subset, False, q[i]))
                if a < 2:
                    print(2)
                    flag = True
                    break
        if flag:
            break
    if flag:
        continue
    for i in range(3):
        j, k = (i + 1) % 3, (i + 2) % 3
        if x[j] != 0 and x[k] != 0 and eq((y[j] - d[i]) / x[j], (y[k] - d[i]) / x[k]) and ((y[j] - d[i]) / x[j]) % 1 == 0:
            print(2)
            flag = True
            break
    if flag:
        continue
    if x[0] != x[1] and eq((y[0] - y[1]) / (x[0] - x[1]), (y[0] - y[2]) / (x[0] - x[2])):
        print(2)
        continue
    print(3)

def d1d2(p,q,r,a,b,c):
    if p == 0 or q == 0 or r == 0:
        return False
    if a%p == 0 and b % q == 0:
        d1 = a//p
        d2 = b//q
        if c == r * d1 * d2:
            return True
        return False
    return False
    
def e1e2(p,q,r,a,b,c):
    e1 = a - p
    e2 = b - q
    return c == r + e1 + e2
        
def d3e3(p,q,r,a,b,c):
    delta = [0, 0, 0]
    delta[0] = p - q
#     print(f'1.{delta=}')
    if delta[0] == 0:
        return False
        # explanation:
        # for infinite no of sols a = b; but q = p(delta[0] == 0) sol 2 same case (already handled) not considering here
    delta[1] = a - b
    delta[2] = p*b - q*a
#     print(f'2.{delta=}')
    if delta[1] % delta[0] == 0 and delta[2] % delta[0] == 0:
        val_d = delta[1]//delta[0]
        val_e = delta[2]//delta[0]
        return  c == r * val_d + val_e
            
    else:
        #e and d are not integer solutions
        return False
         
def d3e2(p,q,r,a,b,c):
    #assuming a,b eq has same form
    delta = [0, 0, 0]
    delta[0] = p - q
    if delta[0] == 0:
        return False
        # explanation:
        # for infinite no of sols a = b; but q = p(delta[0] == 0) sol 2 same case (already handled) not considering here
    delta[1] = a - b
    delta[2] = p*b - q*a
#     print(f'Δ0 = {delta[0]} Δ1 = {delta[1]} Δ2 = {delta[2]}')
    if delta[1] % delta[0] == 0 and delta[2] % delta[0] == 0:
        val_d = delta[1]//delta[0]
        val_e = delta[2]//delta[0]
#         print(f'd = {val_d} e = {val_e}')
        return  c == r * val_d
            
    else:
        #e and d are not integer solutions
        return False
        
def d2e3(p,q,r,a,b,c):
    #assuming a,b eq has same form
    
    delta = [0, 0, 0]
    delta[0] = p - q
    if delta[0] == 0:
        return False
        # explanation:
        # for infinite no of sols a = b; but q = p(delta[0] == 0) sol 2 same case (already handled) not considering here
    delta[1] = a - b
    delta[2] = p*b - q*a

    if delta[1] % delta[0] == 0 and delta[2] % delta[0] == 0:
        val_d = delta[1]//delta[0]
        val_e = delta[2]//delta[0]
        return  c == r + val_e
            
    else:
        #e and d are not integer solutions
        return False
        
'''
two case: 1. a = pd + e, b = qd + e, c = r (already handled 1 same)
2. a = pd + e, b = qd, c = r + e
'''
def d2e2(p,q,r,a,b,c):
    if q != 0 and b % q == 0:
        d = b//q
        e = c - r
        assert e != 0, "already checked, one same"
        return a == p*d + e
    return False

def e3d2(p,q,r,a,b,c):
    assert c!=r, "1 same"
    e = c - r
    if p != -e and q !=-e and a % (p + e) == 0 and b % (q + e) == 0:# p + e != 0 as then a = 0 and 1 difference case or no soln
        d1 = a//(p + e)
        d2 = b//(q + e)
        return d1 != 1 and d1 == d2
    return False
    
def e2d2(p,q,r,a,b,c):
    if r != 0 and c % r == 0:
        d = c//r
        e = b - q
        assert d != 1 and e != 0, '1 or 2 same'
        return a == (p + e) * d
    return False
    
def modified(src, dst):
    p,q,r = src
    a,b,c = dst
    # print(p,q,r), '-->',(a,b,c)
    
    #case 1: some are same
    #case 1.0: all are same then 0 chances:
    if p == a and q == b and r == c:
        print(0)
        return
    #case 1.1:if two are same
    # p,q
    if p == a and q == b:
        if r != c:
            print(1)
            return
        assert True, "Should not have come here1"
    # q,r
    if q == b and r == c:
        if p != a:
            print(1)
            return
        assert True, "Should not have come here2"
    # r,p
    if r == c and p == a:
        if q != b:
            print(1)
            return
        assert True, "Should not have come here3"
        
    #case 1.3 any one is same
    # p
    if p == a:
        if b - q == c - r:
            print(1)
            return
        if q != 0 and r != 0 and b%q == 0 and b%q == c%r and b//q == c//r:
            print(1)
            return
        print(2)
        return
    if q == b:
        if c - r == a - p:
            print(1)
            return
        if p != 0 and r != 0 and a%p == 0 and  a%p == c%r and a//p == c//r:
            print(1)
            return
        print(2)
        return
        
    if r == c:
        if b - q == a - p:
            print(1)
            return
        if p != 0 and q != 0 and a%p == 0 and  a%p == b%q and a//p == b//q:
            print(1)
            return
        print(2)
        return        
    #case 2: all are different
    #case 2.1: all are at same difference : 2 same ratio/ difference
    if p-a == q-b and q-b == r-c:
        print(1)
        return
    #or at same ratio
    if p!=0 and q!= 0 and r!=0:
        if a%p == 0 and a%p == b%q and b%q == c%r:
            if a//p == b//q and b//q == c//r:
                print(1)
                return
    #if any two has same difference or ratio
    #case 2.2: 1 same ratio/difference
    # p,q
    if p-a == q-b :
        print(2)
        return
    if p!=0 and q!=0 and a%p == 0 and a%p == b%q and a//p == b//q:
        print(2)
        return
    # q,r
    if r-c == q-b :
        print(2)
        return
    if r!=0 and q!=0 and c%r == 0 and c%r == b%q and c//r == b//q:
        print(2)
        return    
    
    # r,p
    if p-a == r-c :
        print(2)
        return
    if p!=0 and r!=0 and a%p == 0 and a%p == c%r and a//p == c//r:
        print(2)
        return
    
    
    #case 3: nothing is same no two has same difference or ration
    #case 3.0: pd1 qd2 rd1d2 form
    if d1d2(p,q,r,a,b,c) or d1d2(q,r,p,b,c,a) or d1d2(r,p,q,c,a,b):
        print(2)
        return
    #case 3.1: p + e1 q + e2 r + e1 + e2 form
    if e1e2(p,q,r,a,b,c) or e1e2(q,r,p,b,c,a) or e1e2(r,p,q,c,a,b):
        print(2)
        return
    #case 3.2: pd + e forms
    #case 3.2.1: 3d3e
    if d3e3(p,q,r,a,b,c):
        print(2)
        return
    #case 3.2.2: 3d2e
    if d3e2(p,q,r,a,b,c) or d3e2(q,r,p,b,c,a) or d3e2(r,p,q,c,a,b):
        print(2)
        return
    
    #case 3.2.3: 2d3e
    if d2e3(p,q,r,a,b,c) or d2e3(q,r,p,b,c,a) or d2e3(r,p,q,c,a,b):
        print(2)
        return
    if d2e2(p,q,r,a,b,c) or d2e2(q,r,p,b,c,a) or d2e2(r,p,q,c,a,b) or d2e2(p,r,q,a,c,b) or d2e2(q,p,r,b,a,c) or d2e2(r,q,p,c,b,a):
        print(2)
        return
    if e3d2(p,q,r,a,b,c) or e3d2(q,r,p,b,c,a) or e3d2(r,p,q,c,a,b):
        print(2)
        return
    if e2d2(p,q,r,a,b,c) or e2d2(q,r,p,b,c,a) or e2d2(r,p,q,c,a,b) or e2d2(p,r,q,a,c,b) or e2d2(q,p,r,b,a,c) or e2d2(r,q,p,c,b,a):
        print(2)
        return
    print(3)
    
for _ in range(int(input())):
    src = tuple(map(int, input().split()))
    dst = tuple(map(int, input().split()))
    modified(src, dst)
    # print(modified(src, dst))

def aa22(p,q,r,a,b,c):
    if(q+a-p+c-r == b):
        return 1
    else:
        return 0
def aa21(p,q,r,a,b,c):
    if(p-q==a-b):
        return 1
    else:
        return 0
def as22(p,q,r,a,b,c):
    if((p+b-c+r-q)==a):
        return 1
    else:
        return 0
def am22(p,q,r,a,b,c):
    if(r!=0 and c!=0 and c%r==0 and  (b*r)%c==0 and ((b*r)//c)-q==(a-p)):
        return 1
    else:
        return 0
def am21(p,q,r,a,b,c):
    if((r!=0) and c%r==0 and (p-q)==(a-b)):
        return 1
    else:
        return 0
def am23(p,q,r,a,b,c):
    if((r!=0) and (c!=0)  and (c%r)==0  and  (b*r)%c==0 and (a*r)%c==0 and  ((a*r)//c)-p==((b*r)//c)-q):
        return 1
    else:
        return 0
def am32(p,q,r,a,b,c):
    if((q+c-r)!=0 and (p+c-r)!=0 and (b//(q+c-r))==(a//(p+c-r)) and b%(q+c-r)==0 and a%(p+c-r)==0):
        return 1
    else:
        return 0
def ma33(p,q,r,a,b,c):
    if((p-q)!=0 and  ((b*p)-(a*q))%(p-q)==0 and (q-r)!=0 and p!=0 and  ((c*q)-(b*r))%(q-r)==0 and ((b*p)-(a*q))//(p-q)==((c*q)-(b*r))//(q-r) and (a-(((b*p)-(a*q))//(p-q)))%p==0):
        return 1
    else:
        return 0
def am33(p,q,r,a,b,c):
    if((a-b)!=0  and ((b*p)-(a*q))%(a-b)==0 and (b-c)!=0  and ((c*q)-(b*r))%(b-c)==0 and ((b*p)-(a*q))//(a-b)==((c*q)-(b*r))//(b-c) and  (p+(((b*p)-(a*q))//(a-b)))!=0 and a%(p+(((b*p)-(a*q))//(a-b)))==0):
        return 1
    else:
        return 0
def ma22(p,q,r,a,b,c):
    if((p!=0)  and q!=0  and (a%p)==0  and (b-c+r)%q==0 and (a//p)==((b-c+r)//q)):
        return 1
    else:
        return 0
def ma21(p,q,r,a,b,c):
    if((p!=0) and (q!=0) and (a%p)==0 and (b%q)==0 and (a//p)==(b//q)):
        return 1
    else:
        return 0
def ma23(p,q,r,a,b,c):
    if((q!=0) and (p!=0)  and (b-c+r)%q==0 and (a-c+r)%p==0 and ((b-c+r)//q)==((a-c+r)//p)):
        return 1
    else:
        return 0
def ma32(p,q,r,a,b,c):
    if(r!=0  and (q*c)%r==0 and (p*c)%r==0 and b-((q*c)//r)==a-((p*c)//r)  and (c%r)==0):
        return 1
    else:
        return 0
def ms22(p,q,r,a,b,c):
    if((q!=0) and (p!=0)  and ((b+r-c)%q)==0 and (a%p)==0 and ((b+r-c)//q)==(a//p)):
        return 1
    else:
        return 0
def mm22(p,q,r,a,b,c):
    if((q*c)!=0  and (b*r)%(q*c)==0 and (p!=0) and a%p==0 and  (a//p)==((b*r)//(q*c))):
        return 1
    else:
        return 0
def mm21(p,q,r,a,b,c):
    if((r!=0) and (c%r==0) and (q!=0) and (p!=0) and (b//q)==(a//p) and (b%q)==0 and (a%p)==0):
        return 1
    else:
        return 0
def sa22(p,q,r,a,b,c):
    if((q-b+c-r)==(p-a)):
        return 1
    else:
        return 0
def sa21(p,q,r,a,b,c):
    if((p-a)==(q-b)):
        return 1
    else:
        return 0
def sm32(p,q,r,a,b,c):
    if((q-r+c)!=0  and (p-r+c)!=0 and (b//(q-r+c))==(a//(p-r+c)) and b%(q-r+c)==0 and a%(p-r+c)==0):
        return 1
    else:
        return 0
def as2(q,r,b,c):
    if((q-r) == (b-c)):
        return 1
    else:
        return 0
def m2(q,r,b,c):
    if(r!=0  and q!=0  and  (b//q)==(c//r) and (b%q)==0 and (c%r)==0):
        return 1
    else:
        return 0
def as3(p,q,r,a,b,c):
    if(p-q == a-b and q-r == b-c and p-r == a-c):
        return 1
    else:
        return 0
def m3(p,q,r,a,b,c):
    if(q!=0  and r!=0 and p!=0 and (a//p)==(b//q) and (b//q)==(c//r) and (a%p)==0 and (b%q)==0 and c%r==0):
        return 1
    else:
        return 0
t=int(input())
while(t>0):
    p,q,r=map(int,input().split())
    a,b,c=map(int,input().split())
    l=[]
    d=[]
    l3=[]
    l.append(p)
    l.append(q)
    l.append(r)
    l.append(p)
    l.append(r)
    l.append(q)
    l.append(q)
    l.append(p)
    l.append(r)
    l.append(q)
    l.append(r)
    l.append(p)
    l.append(r)
    l.append(p)
    l.append(q)
    l.append(r)
    l.append(q)
    l.append(p)
    l3.append(a)
    l3.append(b)
    l3.append(c)
    l3.append(a)
    l3.append(c)
    l3.append(b)
    l3.append(b)
    l3.append(a)
    l3.append(c)
    l3.append(b)
    l3.append(c)
    l3.append(a)
    l3.append(c)
    l3.append(a)
    l3.append(b)
    l3.append(c)
    l3.append(b)
    l3.append(a)
    l2=[]
    l4=[]
    if(p==a):
        l2.append(q)
        l2.append(r)
        l4.append(b)
        l4.append(c)
    if(q==b):
        l2.append(p)
        l2.append(r)
        l4.append(a)
        l4.append(c)
    if(r==c):
        l2.append(p)
        l2.append(q)
        l4.append(a)
        l4.append(b)
    sol=0
    ans=0
    cnt=(p==a)+(q==b)+(r==c)
    if(p==a and q==b and r==c):
        ans=4
    elif(cnt==2):
        ans=1
    else:
        if(cnt==1):
            for i in range(0,2,2):
                sol=as2(l2[i],l2[i+1],l4[i],l4[i+1])
                if(sol==1):
                    break
                sol=m2(l2[i],l2[i+1],l4[i],l4[i+1])
                if(sol==1):
                    break
            if(sol==1):
                ans=1
                sol=0
            else:
                ans=2
        elif(cnt==0 and ans==0):
            sol=as3(p,q,r,a,b,c)
            if(sol==1):
                ans=1
            sol=m3(p,q,r,a,b,c)
            if(sol==1):
                ans=1
    sol=0
    for  i in range(0,16,3):
        if(ans!=0):
            break
        sol=aa22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=aa21(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=as22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=am22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=am21(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=am23(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=am32(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=ma33(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=am33(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=ma22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=ma21(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=ma23(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=ma32(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=ms22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=mm22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=mm21(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=sa22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
        sol=sm32(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])
        if(sol==1):
            break
    if(sol==1 and ans==0):
        ans=2
    elif(ans==0 and sol!=1):
        ans=3
    if(ans==4):
        print("0")
    else:
        print(ans)
    t=t-1

def checkpoint1(p,q,r,a,b,c):
    if p==a and b-q==c-r :
        return True
    if q==b and a-p==c-r :
        return True
    if c==r and a-p==b-q:
        return True
    if p==a and q==b :
        return True
    if p==a and c==r :
        return True
    if c==r and b==q :
        return True
    if a-p==b-q and a-p==c-r :
        return True
    if q!=0 and r!=0 and b%q==0 and c%r==0 and p==a and b/q==c/r :
        return True
    if p!=0 and r!=0 and a%p==0 and c%r==0 and q==b and a/p==c/r :
        return True
    if p!=0 and q!=0 and a%p==0 and b%q==0 and c==r and a/p==b/q :
        return True  
    if p!=0 and q!=0 and r!=0 and a%p==0 and b%q==0 and c%r==0 and a/p==b/q and a/p==c/r:
        return True 
    return False
def checkpoint2(p,q,r,a,b,c):
    x1=a-p
    y1=b-q
    z1=c-r
    if p==a or q==b or r==c :
        return True
    if a-p==b-q or b-q==c-r or c-r==a-p :
        return True
    if p!=0 and q!=0 and ( a%p==0 and b%q==0 ) and ( a/p==b/q ) :
        return True
    if p!=0 and r!=0 and ( a%p==0 and c%r==0 ) and ( a/p==c/r ) :
        return True
    if q!=0 and r!=0 and ( b%q==0 and c%r==0 ) and ( b/q==c/r ) :
        return True
    if p!=0 and q!=0 and r!=0 and a%p==0 and b%q==0 and c%r==0 and ( a/p*b/q==c/r or a/p*c/r==b/q or b/q*c/r==a/p ) :
        return True
    if x1+y1==z1 or x1+z1==y1 or y1+z1==x1 :
        return True
    if (q+x1)!=0 and r!=0 and b%(q+x1)==0 and c%r==0 and b/(q+x1)==c/r :
        return True
    if p!=0 and a%p==0 and b-(q*a/p)==c-r :
        return True
    if (q+z1)!=0 and p!=0 and b%(q+z1)==0 and a%p==0 and b/(q+z1)==a/p:
        return True
    if r!=0 and c%r==0 and b-(q*c/r)==a-p :
        return True
    if (p+y1)!=0 and r!=0 and a%(p+y1)==0 and c%r==0 and a/(p+y1)==c/r :
        return True
    if q!=0 and b%q==0 and  a-(p*b/q)==c-r :
        return True
    if (p+z1)!=0 and q!=0 and a%(p+z1)==0 and b%q==0 and a/(p+z1)==b/q :
        return True
    if r!=0 and c%r==0 and a-(p*c/r)==b-q :
        return True
    if (r+y1)!=0 and p!=0 and c%(r+y1)==0 and a%p==0 and c/(r+y1)==a/p :
        return True
    if q!=0 and b%q==0 and c-(r*b/q )==a-p :
        return True
    if (r+x1)!=0 and q!=0 and c%(r+x1)==0 and b%q==0 and c/(r+x1)==b/q :
        return True
    if p!=0 and a%p==0 and c-(r*a/p)==b-q :
        return True
    if (p+z1)!=0 and (q+z1)!=0 and a%(p+z1)==0 and b%(q+z1)==0 and a/(p+z1)==b/(q+z1) :
        return True
    if r!=0 and c%r==0 and a-(p*c/r)==b-(q*c/r) :
        return True
    if (p+y1)!=0 and (r+y1)!=0 and a%(p+y1)==0 and c%(r+y1)==0 and a/(p+y1)==c/(r+y1) :
        return True
    if q!=0 and b%q==0 and a-(p*b/q)==c-(r*b/q) :
        return True
    if (q+x1)!=0 and (r+x1)!=0 and b%(q+x1)==0 and c%(r+x1)==0 and b/(q+x1)==c/(r+x1) :
        return True
    if p!=0 and a%p==0 and b-(q*a/p)==c-(r*a/p) :
        return True
    if r!=0 and c%r==0 and c/r!=0 and a%(c/r)==0 and b%(c/r)==0 and a/(c/r)-p==b/(c/r)-q :
        return True
    if p!=0 and q!=0 and (a-z1)%p==0 and (b-z1)%q==0 and (a-z1)/p==(b-z1)/q :
        return True
    if q!=0 and b%q==0 and b/q!=0 and a%(b/q)==0 and c%(b/q)==0 and a/(b/q)-p==c/(b/q)-r : 
        return True
    if p!=0 and r!=0 and (a-y1)%p==0 and (c-y1)%r==0 and (a-y1)/p==(c-y1)/r :
        return True
    if p!=0 and a%p==0 and a/p!=0 and b%(a/p)==0 and c%(a/p)==0 and b/(a/p)-q==c/(a/p)-r : 
        return True
    if q!=0 and r!=0 and (b-x1)%q==0 and (c-x1)%r==0 and (b-x1)/q==(c-x1)/r :
        return True 
    if (q-p)!=0 and (r-q)!=0 and (b-a)%(q-p)==0 and (c-b)%(r-q)==0 and (b-a)/(q-p)==(c-b)/(r-q):
       return True
    return False
test=int(input())
for _ in range(test):
    x1,y1,z1=[int(x) for x in input().split()]
    a,b,c=[int(x) for x in input().split()]
    if a==x1 and b==y1 and c==z1:
        print(0)
    elif checkpoint1(x1,y1,z1,a,b,c):
        print(1)
    elif checkpoint2(x1,y1,z1,a,b,c):
        print(2)
    else:
        print(3)

def checkpoint1(p,q,r,a,b,c):
    if p==a and b-q==c-r :
        return True
    if q==b and a-p==c-r :
        return True
    if c==r and a-p==b-q:
        return True
    if p==a and q==b :
        return True
    if p==a and c==r :
        return True
    if c==r and b==q :
        return True
    if a-p==b-q and a-p==c-r :
        return True
    if q!=0 and r!=0 and b%q==0 and c%r==0 and p==a and b/q==c/r :
        return True
    if p!=0 and r!=0 and a%p==0 and c%r==0 and q==b and a/p==c/r :
        return True
    if p!=0 and q!=0 and a%p==0 and b%q==0 and c==r and a/p==b/q :
        return True  
    if p!=0 and q!=0 and r!=0 and a%p==0 and b%q==0 and c%r==0 and a/p==b/q and a/p==c/r:
        return True 
    return False
def checkpoint2(p,q,r,a,b,c):
    x1=a-p
    y1=b-q
    z1=c-r
    if p==a or q==b or r==c :
        return True
    if a-p==b-q or b-q==c-r or c-r==a-p :
        return True
    if p!=0 and q!=0 and ( a%p==0 and b%q==0 ) and ( a/p==b/q ) :
        return True
    if p!=0 and r!=0 and ( a%p==0 and c%r==0 ) and ( a/p==c/r ) :
        return True
    if q!=0 and r!=0 and ( b%q==0 and c%r==0 ) and ( b/q==c/r ) :
        return True
    if p!=0 and q!=0 and r!=0 and a%p==0 and b%q==0 and c%r==0 and ( a/p*b/q==c/r or a/p*c/r==b/q or b/q*c/r==a/p ) :
        return True
    if x1+y1==z1 or x1+z1==y1 or y1+z1==x1 :
        return True
    if (q+x1)!=0 and r!=0 and b%(q+x1)==0 and c%r==0 and b/(q+x1)==c/r :
        return True
    if p!=0 and a%p==0 and b-(q*a/p)==c-r :
        return True
    if (q+z1)!=0 and p!=0 and b%(q+z1)==0 and a%p==0 and b/(q+z1)==a/p:
        return True
    if r!=0 and c%r==0 and b-(q*c/r)==a-p :
        return True
    if (p+y1)!=0 and r!=0 and a%(p+y1)==0 and c%r==0 and a/(p+y1)==c/r :
        return True
    if q!=0 and b%q==0 and  a-(p*b/q)==c-r :
        return True
    if (p+z1)!=0 and q!=0 and a%(p+z1)==0 and b%q==0 and a/(p+z1)==b/q :
        return True
    if r!=0 and c%r==0 and a-(p*c/r)==b-q :
        return True
    if (r+y1)!=0 and p!=0 and c%(r+y1)==0 and a%p==0 and c/(r+y1)==a/p :
        return True
    if q!=0 and b%q==0 and c-(r*b/q )==a-p :
        return True
    if (r+x1)!=0 and q!=0 and c%(r+x1)==0 and b%q==0 and c/(r+x1)==b/q :
        return True
    if p!=0 and a%p==0 and c-(r*a/p)==b-q :
        return True
    if (p+z1)!=0 and (q+z1)!=0 and a%(p+z1)==0 and b%(q+z1)==0 and a/(p+z1)==b/(q+z1) :
        return True
    if r!=0 and c%r==0 and a-(p*c/r)==b-(q*c/r) :
        return True
    if (p+y1)!=0 and (r+y1)!=0 and a%(p+y1)==0 and c%(r+y1)==0 and a/(p+y1)==c/(r+y1) :
        return True
    if q!=0 and b%q==0 and a-(p*b/q)==c-(r*b/q) :
        return True
    if (q+x1)!=0 and (r+x1)!=0 and b%(q+x1)==0 and c%(r+x1)==0 and b/(q+x1)==c/(r+x1) :
        return True
    if p!=0 and a%p==0 and b-(q*a/p)==c-(r*a/p) :
        return True
    if r!=0 and c%r==0 and c/r!=0 and a%(c/r)==0 and b%(c/r)==0 and a/(c/r)-p==b/(c/r)-q :
        return True
    if p!=0 and q!=0 and (a-z1)%p==0 and (b-z1)%q==0 and (a-z1)/p==(b-z1)/q :
        return True
    if q!=0 and b%q==0 and b/q!=0 and a%(b/q)==0 and c%(b/q)==0 and a/(b/q)-p==c/(b/q)-r : 
        return True
    if p!=0 and r!=0 and (a-y1)%p==0 and (c-y1)%r==0 and (a-y1)/p==(c-y1)/r :
        return True
    if p!=0 and a%p==0 and a/p!=0 and b%(a/p)==0 and c%(a/p)==0 and b/(a/p)-q==c/(a/p)-r : 
        return True
    if q!=0 and r!=0 and (b-x1)%q==0 and (c-x1)%r==0 and (b-x1)/q==(c-x1)/r :
        return True 
    if (q-p)!=0 and (r-q)!=0 and (b-a)%(q-p)==0 and (c-b)%(r-q)==0 and (b-a)/(q-p)==(c-b)/(r-q):
       return True
    return False
test=int(input())
for _ in range(test):
    x1,y1,z1=[int(x) for x in input().split()]
    a,b,c=[int(x) for x in input().split()]
    if a==x1 and b==y1 and c==z1:
        print(0)
    elif checkpoint1(x1,y1,z1,a,b,c):
        print(1)
    elif checkpoint2(x1,y1,z1,a,b,c):
        print(2)
    else:
        print(3)

t=int(input())
while t>0:
    li1=[int(i) for i in input().split()]
    li2=[int(i) for i in input().split()]
    s1=set()
    s2=set()
    val,ans=0,3
    for i in range(3):
        if li1[i]==li2[i]:
            val+=1
    if val==3:
        ans=0
    elif val==2:
        ans=1
    else:
        for i in range(3):
            if li2[i]-li1[i]!=0:
                s1.add(li2[i]-li1[i])
            if li1[i]!=0 and li2[i]%li1[i]==0 and li2[i]//li1[i]!=1:
                s2.add(li2[i]//li1[i])
        temp=[]
        for i in s1:
            for j in range(7):
                temp=[li1[k] for k in range(3)]
                if j==0:
                    temp[0]+=i
                    temp[1]+=i
                elif j==1:
                    temp[0]+=i
                    temp[2]+=i
                elif j==2:
                    temp[1]+=i
                    temp[2]+=i
                elif j==3:
                    temp[0]+=i
                    temp[1]+=i
                    temp[2]+=i
                elif j==4:
                    temp[0]+=i
                elif j==5:
                    temp[1]+=i
                elif j==6:
                    temp[2]+=i
                a=0
                for k in range(3):
                    if temp[k]==li2[k]:
                        a+=1
                if a==3:
                    ans=1
                if a==2:
                    ans=min(ans,2)
                s3=set()
                for k in range(3):
                    if temp[k]!=0 and li2[k]%temp[k]==0 and li2[k]//temp[k]!=1:
                        s3.add(li2[k]//temp[k])
                temp1=[]
                for k in s3:
                    for l in range(7):
                        temp1=[temp[m] for m in range(3)]
                        if l==0:
                            temp1[0]*=k
                            temp1[1]*=k
                        elif l==1:
                            temp1[0]*=k
                            temp1[2]*=k
                        elif l==2:
                            temp1[1]*=k
                            temp1[2]*=k
                        elif l==3:
                            temp1[0]*=k
                            temp1[1]*=k
                            temp1[2]*=k
                        elif l==4:
                            temp1[0]*=k
                        elif l==5:
                            temp1[1]*=k
                        elif l==6:
                            temp1[2]*=k
                        for m in range(3):
                            if li2[m]!=temp1[m]:
                                break
                            if m==2:
                                ans=min(ans,2)
                s4=set()
                for k in range(3):
                    if li2[k]-temp[k]!=0:
                        s4.add(li2[k]-temp[k])
                temp2=[]
                for k in s4:
                    for l in range(7):
                        temp2=[temp[m] for m in range(3)]
                        if l==0:
                            temp2[0]+=k
                            temp2[1]+=k
                        elif l==1:
                            temp2[0]+=k
                            temp2[2]+=k
                        elif l==2:
                            temp2[1]+=k
                            temp2[2]+=k
                        elif l==3:
                            temp2[0]+=k
                            temp2[1]+=k
                            temp2[2]+=k
                        elif l==4:
                            temp2[0]+=k
                        elif l==5:
                            temp2[1]+=k
                        elif l==6:
                            temp2[2]+=k
                        for m in range(3):
                            if li2[m]!=temp2[m]:
                                break
                            if m==2:
                                ans=min(ans,2)
                s4.clear()
                count=0
                for k in range(3):
                    var=li2[k]-i
                    if li1[k]!=0 and var%li1[k]==0:
                        if var//li1[k]!=1:
                            s4.add(var//li1[k])
                        count+=1
                if len(s4)==1 and count==3:
                    ans=min(ans,2)
        if ans==3 or ans==2:
            d1=li2[2]-li2[1]
            d2=li2[1]-li2[0]
            d3=li1[2]-li1[1]
            d4=li1[1]-li1[0]
            d5=li2[2]-li2[0]
            d6=li1[2]-li1[0]
            if (d3!=0 and d4!=0 and d6!=0 and d1%d3==0 and d2%d4==0 and d5%d6==0 and d1//d3==d2//d4 and d1//d3==d5//d6):
                ans=min(ans,2)
            for i in s2:
                s3=set()
                count=0
                for j in range(3):
                    temp[j]=li2[j]
                    if i!=0 and temp[j]%i==0:
                        temp[j]//=i
                        temp[j]-=li1[j]
                        if temp[j]!=0:
                            s3.add(temp[j])
                        count+=1
                    
                if len(s3)==1 and count==3:
                    ans=min(ans,2)
            for i in s2:
                for j in range(7):
                    temp=[li1[k] for k in range(3)]
                    if j==0:
                        temp[0]*=i
                        temp[1]*=i
                    elif j==1:
                        temp[0]*=i
                        temp[2]*=i
                    elif j==2:
                        temp[1]*=i
                        temp[2]*=i
                    elif j==3:
                        temp[0]*=i
                        temp[1]*=i
                        temp[2]*=i
                    elif j==4:
                        temp[0]*=i
                    elif j==5:
                        temp[1]*=i
                    elif j==6:
                        temp[2]*=i
                    a=0
                    for k in range(3):
                        if temp[k]==li2[k]:
                            a+=1
                    if a==3:
                        ans=1
                    elif a==2:
                        ans=min(ans,2)
                    temp2=[]
                    s4=set()
                    for k in range(3):
                        if temp[k]!=0 and li2[k]%temp[k]==0 and li2[k]//temp[k]!=1:
                            s4.add(li2[k]//temp[k])
                    temp2=[]
                    for k in s4:
                        for l in range(7):
                            temp2=[temp[m] for m in range(3)]
                            if l==0:
                                temp2[0]*=k
                                temp2[1]*=k
                            elif l==1:
                                temp2[0]*=k
                                temp2[2]*=k
                            elif l==2:
                                temp2[1]*=k
                                temp2[2]*=k
                            elif l==3:
                                temp2[0]*=k
                                temp2[1]*=k
                                temp2[2]*=k
                            elif l==4:
                                temp2[0]*=k
                            elif l==5:
                                temp2[1]*=k
                            elif l==6:
                                temp2[2]*=k
                            for m in range(3):
                                if li2[m]!=temp2[m]:
                                    break
                                if m==2:
                                    ans=min(ans,2)
                    s4.clear()
                    for k in range(3):
                        var=li2[k]-temp[k]
                        if var!=0:
                            s4.add(var)
                    if len(s4)==1:
                        ans=min(ans,2)
    print(ans)
    t-=1


def util(x1, x2, y1, y2):
    d = x1 - y1
    n = x2 - y2
    if d and not n%d:
        return n//d
    return 1

def solve(p, q, r, a, b, c, res=0):
    if p == a and q == b and r == c:
        return res
    if res >= 2:
        return 3
    adds = [a-p, b-q, c-r]
    muls = []
    if p and not a%p:
        muls += [a//p]
    if q and not b%q:
        muls += [b//q]
    if r and not c%r:
        muls += [c//r]
    muls.append(util(p, a, q, b))
    muls.append(util(p, a, r, c))
    muls.append(util(q, b, r, c))
    mask = 2**3
    ans = 3
    for msk in range(1, mask):
        for add in adds:
            np, nq, nr = p, q, r
            if msk & 1:
                np += add
            if msk & 2:
                nq += add
            if msk & 4:
                nr += add
            ans = min(ans, solve(np, nq, nr, a, b, c, res+1))
        for mul in muls:
            np, nq, nr = p, q, r
            if msk & 1:
                np *= mul
            if msk & 2:
                nq *= mul
            if msk & 4:
                nr *= mul
            ans = min(ans, solve(np, nq, nr, a, b, c, res+1))
    return ans

def main():
    t = int(input())
    for i in range(t):
        p, q, r = map(int, input().split())
        a, b, c = map(int, input().split())
        print(solve(p, q, r, a, b, c))

def __starting_point():
    main()

__starting_point()