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

```

Measured memory_bytes: 14437