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$.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'def aa22(p,q,r,a,b,c):\n    if(q+a-p+c-r == b):\n        return 1\n    else:\n        return 0\ndef aa21(p,q,r,a,b,c):\n    if(p-q==a-b):\n        return 1\n    else:\n        return 0\ndef as22(p,q,r,a,b,c):\n    if((p+b-c+r-q)==a):\n        return 1\n    else:\n        return 0\ndef am22(p,q,r,a,b,c):\n    if(r!=0 and c!=0 and c%r==0 and  (b*r)%c==0 and ((b*r)//c)-q==(a-p)):\n        return 1\n    else:\n        return 0\ndef am21(p,q,r,a,b,c):\n    if((r!=0) and c%r==0 and (p-q)==(a-b)):\n        return 1\n    else:\n        return 0\ndef am23(p,q,r,a,b,c):\n    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):\n        return 1\n    else:\n        return 0\ndef am32(p,q,r,a,b,c):\n    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):\n        return 1\n    else:\n        return 0\ndef ma33(p,q,r,a,b,c):\n    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):\n        return 1\n    else:\n        return 0\ndef am33(p,q,r,a,b,c):\n    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):\n        return 1\n    else:\n        return 0\ndef ma22(p,q,r,a,b,c):\n    if((p!=0)  and q!=0  and (a%p)==0  and (b-c+r)%q==0 and (a//p)==((b-c+r)//q)):\n        return 1\n    else:\n        return 0\ndef ma21(p,q,r,a,b,c):\n    if((p!=0) and (q!=0) and (a%p)==0 and (b%q)==0 and (a//p)==(b//q)):\n        return 1\n    else:\n        return 0\ndef ma23(p,q,r,a,b,c):\n    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)):\n        return 1\n    else:\n        return 0\ndef ma32(p,q,r,a,b,c):\n    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):\n        return 1\n    else:\n        return 0\ndef ms22(p,q,r,a,b,c):\n    if((q!=0) and (p!=0)  and ((b+r-c)%q)==0 and (a%p)==0 and ((b+r-c)//q)==(a//p)):\n        return 1\n    else:\n        return 0\ndef mm22(p,q,r,a,b,c):\n    if((q*c)!=0  and (b*r)%(q*c)==0 and (p!=0) and a%p==0 and  (a//p)==((b*r)//(q*c))):\n        return 1\n    else:\n        return 0\ndef mm21(p,q,r,a,b,c):\n    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):\n        return 1\n    else:\n        return 0\ndef sa22(p,q,r,a,b,c):\n    if((q-b+c-r)==(p-a)):\n        return 1\n    else:\n        return 0\ndef sa21(p,q,r,a,b,c):\n    if((p-a)==(q-b)):\n        return 1\n    else:\n        return 0\ndef sm32(p,q,r,a,b,c):\n    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):\n        return 1\n    else:\n        return 0\ndef as2(q,r,b,c):\n    if((q-r) == (b-c)):\n        return 1\n    else:\n        return 0\ndef m2(q,r,b,c):\n    if(r!=0  and q!=0  and  (b//q)==(c//r) and (b%q)==0 and (c%r)==0):\n        return 1\n    else:\n        return 0\ndef as3(p,q,r,a,b,c):\n    if(p-q == a-b and q-r == b-c and p-r == a-c):\n        return 1\n    else:\n        return 0\ndef m3(p,q,r,a,b,c):\n    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):\n        return 1\n    else:\n        return 0\nt=int(input())\nwhile(t>0):\n    p,q,r=map(int,input().split())\n    a,b,c=map(int,input().split())\n    l=[]\n    d=[]\n    l3=[]\n    l.append(p)\n    l.append(q)\n    l.append(r)\n    l.append(p)\n    l.append(r)\n    l.append(q)\n    l.append(q)\n    l.append(p)\n    l.append(r)\n    l.append(q)\n    l.append(r)\n    l.append(p)\n    l.append(r)\n    l.append(p)\n    l.append(q)\n    l.append(r)\n    l.append(q)\n    l.append(p)\n    l3.append(a)\n    l3.append(b)\n    l3.append(c)\n    l3.append(a)\n    l3.append(c)\n    l3.append(b)\n    l3.append(b)\n    l3.append(a)\n    l3.append(c)\n    l3.append(b)\n    l3.append(c)\n    l3.append(a)\n    l3.append(c)\n    l3.append(a)\n    l3.append(b)\n    l3.append(c)\n    l3.append(b)\n    l3.append(a)\n    l2=[]\n    l4=[]\n    if(p==a):\n        l2.append(q)\n        l2.append(r)\n        l4.append(b)\n        l4.append(c)\n    if(q==b):\n        l2.append(p)\n        l2.append(r)\n        l4.append(a)\n        l4.append(c)\n    if(r==c):\n        l2.append(p)\n        l2.append(q)\n        l4.append(a)\n        l4.append(b)\n    sol=0\n    ans=0\n    cnt=(p==a)+(q==b)+(r==c)\n    if(p==a and q==b and r==c):\n        ans=4\n    elif(cnt==2):\n        ans=1\n    else:\n        if(cnt==1):\n            for i in range(0,2,2):\n                sol=as2(l2[i],l2[i+1],l4[i],l4[i+1])\n                if(sol==1):\n                    break\n                sol=m2(l2[i],l2[i+1],l4[i],l4[i+1])\n                if(sol==1):\n                    break\n            if(sol==1):\n                ans=1\n                sol=0\n            else:\n                ans=2\n        elif(cnt==0 and ans==0):\n            sol=as3(p,q,r,a,b,c)\n            if(sol==1):\n                ans=1\n            sol=m3(p,q,r,a,b,c)\n            if(sol==1):\n                ans=1\n    sol=0\n    for  i in range(0,16,3):\n        if(ans!=0):\n            break\n        sol=aa22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=aa21(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=as22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=am22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=am21(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=am23(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=am32(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=ma33(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=am33(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=ma22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=ma21(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=ma23(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=ma32(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=ms22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=mm22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=mm21(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=sa22(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n        sol=sm32(l[i],l[i+1],l[i+2],l3[i],l3[i+1],l3[i+2])\n        if(sol==1):\n            break\n    if(sol==1 and ans==0):\n        ans=2\n    elif(ans==0 and sol!=1):\n        ans=3\n    if(ans==4):\n        print("0")\n    else:\n        print(ans)\n    t=t-1'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 22019