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

```

Measured memory_bytes: 19027