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 checkpoint1(p,q,r,a,b,c):\r\n    if p==a and b-q==c-r :\r\n        return True\r\n    if q==b and a-p==c-r :\r\n        return True\r\n    if c==r and a-p==b-q:\r\n        return True\r\n    if p==a and q==b :\r\n        return True\r\n    if p==a and c==r :\r\n        return True\r\n    if c==r and b==q :\r\n        return True\r\n    if a-p==b-q and a-p==c-r :\r\n        return True\r\n    if q!=0 and r!=0 and b%q==0 and c%r==0 and p==a and b/q==c/r :\r\n        return True\r\n    if p!=0 and r!=0 and a%p==0 and c%r==0 and q==b and a/p==c/r :\r\n        return True\r\n    if p!=0 and q!=0 and a%p==0 and b%q==0 and c==r and a/p==b/q :\r\n        return True  \r\n    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:\r\n        return True \r\n    return False\r\ndef checkpoint2(p,q,r,a,b,c):\r\n    x1=a-p\r\n    y1=b-q\r\n    z1=c-r\r\n    if p==a or q==b or r==c :\r\n        return True\r\n    if a-p==b-q or b-q==c-r or c-r==a-p :\r\n        return True\r\n    if p!=0 and q!=0 and ( a%p==0 and b%q==0 ) and ( a/p==b/q ) :\r\n        return True\r\n    if p!=0 and r!=0 and ( a%p==0 and c%r==0 ) and ( a/p==c/r ) :\r\n        return True\r\n    if q!=0 and r!=0 and ( b%q==0 and c%r==0 ) and ( b/q==c/r ) :\r\n        return True\r\n    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 ) :\r\n        return True\r\n    if x1+y1==z1 or x1+z1==y1 or y1+z1==x1 :\r\n        return True\r\n    if (q+x1)!=0 and r!=0 and b%(q+x1)==0 and c%r==0 and b/(q+x1)==c/r :\r\n        return True\r\n    if p!=0 and a%p==0 and b-(q*a/p)==c-r :\r\n        return True\r\n    if (q+z1)!=0 and p!=0 and b%(q+z1)==0 and a%p==0 and b/(q+z1)==a/p:\r\n        return True\r\n    if r!=0 and c%r==0 and b-(q*c/r)==a-p :\r\n        return True\r\n    if (p+y1)!=0 and r!=0 and a%(p+y1)==0 and c%r==0 and a/(p+y1)==c/r :\r\n        return True\r\n    if q!=0 and b%q==0 and  a-(p*b/q)==c-r :\r\n        return True\r\n    if (p+z1)!=0 and q!=0 and a%(p+z1)==0 and b%q==0 and a/(p+z1)==b/q :\r\n        return True\r\n    if r!=0 and c%r==0 and a-(p*c/r)==b-q :\r\n        return True\r\n    if (r+y1)!=0 and p!=0 and c%(r+y1)==0 and a%p==0 and c/(r+y1)==a/p :\r\n        return True\r\n    if q!=0 and b%q==0 and c-(r*b/q )==a-p :\r\n        return True\r\n    if (r+x1)!=0 and q!=0 and c%(r+x1)==0 and b%q==0 and c/(r+x1)==b/q :\r\n        return True\r\n    if p!=0 and a%p==0 and c-(r*a/p)==b-q :\r\n        return True\r\n    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) :\r\n        return True\r\n    if r!=0 and c%r==0 and a-(p*c/r)==b-(q*c/r) :\r\n        return True\r\n    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) :\r\n        return True\r\n    if q!=0 and b%q==0 and a-(p*b/q)==c-(r*b/q) :\r\n        return True\r\n    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) :\r\n        return True\r\n    if p!=0 and a%p==0 and b-(q*a/p)==c-(r*a/p) :\r\n        return True\r\n    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 :\r\n        return True\r\n    if p!=0 and q!=0 and (a-z1)%p==0 and (b-z1)%q==0 and (a-z1)/p==(b-z1)/q :\r\n        return True\r\n    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 : \r\n        return True\r\n    if p!=0 and r!=0 and (a-y1)%p==0 and (c-y1)%r==0 and (a-y1)/p==(c-y1)/r :\r\n        return True\r\n    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 : \r\n        return True\r\n    if q!=0 and r!=0 and (b-x1)%q==0 and (c-x1)%r==0 and (b-x1)/q==(c-x1)/r :\r\n        return True \r\n    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):\r\n       return True\r\n    return False\r\ntest=int(input())\r\nfor _ in range(test):\r\n    x1,y1,z1=[int(x) for x in input().split()]\r\n    a,b,c=[int(x) for x in input().split()]\r\n    if a==x1 and b==y1 and c==z1:\r\n        print(0)\r\n    elif checkpoint1(x1,y1,z1,a,b,c):\r\n        print(1)\r\n    elif checkpoint2(x1,y1,z1,a,b,c):\r\n        print(2)\r\n    else:\r\n        print(3)'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13491