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 = 't=int(input())\nwhile t>0:\n    li1=[int(i) for i in input().split()]\n    li2=[int(i) for i in input().split()]\n    s1=set()\n    s2=set()\n    val,ans=0,3\n    for i in range(3):\n        if li1[i]==li2[i]:\n            val+=1\n    if val==3:\n        ans=0\n    elif val==2:\n        ans=1\n    else:\n        for i in range(3):\n            if li2[i]-li1[i]!=0:\n                s1.add(li2[i]-li1[i])\n            if li1[i]!=0 and li2[i]%li1[i]==0 and li2[i]//li1[i]!=1:\n                s2.add(li2[i]//li1[i])\n        temp=[]\n        for i in s1:\n            for j in range(7):\n                temp=[li1[k] for k in range(3)]\n                if j==0:\n                    temp[0]+=i\n                    temp[1]+=i\n                elif j==1:\n                    temp[0]+=i\n                    temp[2]+=i\n                elif j==2:\n                    temp[1]+=i\n                    temp[2]+=i\n                elif j==3:\n                    temp[0]+=i\n                    temp[1]+=i\n                    temp[2]+=i\n                elif j==4:\n                    temp[0]+=i\n                elif j==5:\n                    temp[1]+=i\n                elif j==6:\n                    temp[2]+=i\n                a=0\n                for k in range(3):\n                    if temp[k]==li2[k]:\n                        a+=1\n                if a==3:\n                    ans=1\n                if a==2:\n                    ans=min(ans,2)\n                s3=set()\n                for k in range(3):\n                    if temp[k]!=0 and li2[k]%temp[k]==0 and li2[k]//temp[k]!=1:\n                        s3.add(li2[k]//temp[k])\n                temp1=[]\n                for k in s3:\n                    for l in range(7):\n                        temp1=[temp[m] for m in range(3)]\n                        if l==0:\n                            temp1[0]*=k\n                            temp1[1]*=k\n                        elif l==1:\n                            temp1[0]*=k\n                            temp1[2]*=k\n                        elif l==2:\n                            temp1[1]*=k\n                            temp1[2]*=k\n                        elif l==3:\n                            temp1[0]*=k\n                            temp1[1]*=k\n                            temp1[2]*=k\n                        elif l==4:\n                            temp1[0]*=k\n                        elif l==5:\n                            temp1[1]*=k\n                        elif l==6:\n                            temp1[2]*=k\n                        for m in range(3):\n                            if li2[m]!=temp1[m]:\n                                break\n                            if m==2:\n                                ans=min(ans,2)\n                s4=set()\n                for k in range(3):\n                    if li2[k]-temp[k]!=0:\n                        s4.add(li2[k]-temp[k])\n                temp2=[]\n                for k in s4:\n                    for l in range(7):\n                        temp2=[temp[m] for m in range(3)]\n                        if l==0:\n                            temp2[0]+=k\n                            temp2[1]+=k\n                        elif l==1:\n                            temp2[0]+=k\n                            temp2[2]+=k\n                        elif l==2:\n                            temp2[1]+=k\n                            temp2[2]+=k\n                        elif l==3:\n                            temp2[0]+=k\n                            temp2[1]+=k\n                            temp2[2]+=k\n                        elif l==4:\n                            temp2[0]+=k\n                        elif l==5:\n                            temp2[1]+=k\n                        elif l==6:\n                            temp2[2]+=k\n                        for m in range(3):\n                            if li2[m]!=temp2[m]:\n                                break\n                            if m==2:\n                                ans=min(ans,2)\n                s4.clear()\n                count=0\n                for k in range(3):\n                    var=li2[k]-i\n                    if li1[k]!=0 and var%li1[k]==0:\n                        if var//li1[k]!=1:\n                            s4.add(var//li1[k])\n                        count+=1\n                if len(s4)==1 and count==3:\n                    ans=min(ans,2)\n        if ans==3 or ans==2:\n            d1=li2[2]-li2[1]\n            d2=li2[1]-li2[0]\n            d3=li1[2]-li1[1]\n            d4=li1[1]-li1[0]\n            d5=li2[2]-li2[0]\n            d6=li1[2]-li1[0]\n            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):\n                ans=min(ans,2)\n            for i in s2:\n                s3=set()\n                count=0\n                for j in range(3):\n                    temp[j]=li2[j]\n                    if i!=0 and temp[j]%i==0:\n                        temp[j]//=i\n                        temp[j]-=li1[j]\n                        if temp[j]!=0:\n                            s3.add(temp[j])\n                        count+=1\n                    \n                if len(s3)==1 and count==3:\n                    ans=min(ans,2)\n            for i in s2:\n                for j in range(7):\n                    temp=[li1[k] for k in range(3)]\n                    if j==0:\n                        temp[0]*=i\n                        temp[1]*=i\n                    elif j==1:\n                        temp[0]*=i\n                        temp[2]*=i\n                    elif j==2:\n                        temp[1]*=i\n                        temp[2]*=i\n                    elif j==3:\n                        temp[0]*=i\n                        temp[1]*=i\n                        temp[2]*=i\n                    elif j==4:\n                        temp[0]*=i\n                    elif j==5:\n                        temp[1]*=i\n                    elif j==6:\n                        temp[2]*=i\n                    a=0\n                    for k in range(3):\n                        if temp[k]==li2[k]:\n                            a+=1\n                    if a==3:\n                        ans=1\n                    elif a==2:\n                        ans=min(ans,2)\n                    temp2=[]\n                    s4=set()\n                    for k in range(3):\n                        if temp[k]!=0 and li2[k]%temp[k]==0 and li2[k]//temp[k]!=1:\n                            s4.add(li2[k]//temp[k])\n                    temp2=[]\n                    for k in s4:\n                        for l in range(7):\n                            temp2=[temp[m] for m in range(3)]\n                            if l==0:\n                                temp2[0]*=k\n                                temp2[1]*=k\n                            elif l==1:\n                                temp2[0]*=k\n                                temp2[2]*=k\n                            elif l==2:\n                                temp2[1]*=k\n                                temp2[2]*=k\n                            elif l==3:\n                                temp2[0]*=k\n                                temp2[1]*=k\n                                temp2[2]*=k\n                            elif l==4:\n                                temp2[0]*=k\n                            elif l==5:\n                                temp2[1]*=k\n                            elif l==6:\n                                temp2[2]*=k\n                            for m in range(3):\n                                if li2[m]!=temp2[m]:\n                                    break\n                                if m==2:\n                                    ans=min(ans,2)\n                    s4.clear()\n                    for k in range(3):\n                        var=li2[k]-temp[k]\n                        if var!=0:\n                            s4.add(var)\n                    if len(s4)==1:\n                        ans=min(ans,2)\n    print(ans)\n    t-=1\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 18811