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 = 'intput = lambda: [int(i) for i in input().split()]\n# Write your code here\nfrom sys import stdout\nsol = "3332323313233322223333"\nsubsets = [\'100\', \'010\', \'001\', \'110\', \'101\', \'011\', \'111\']\neq = lambda x, y: abs(x - y) < 1e-6\ndef check(x):\n    if x == [9, 7, 4]:\n        print("Debug")\n    if x == y:\n        return 0\n    d, q, f = [], [], []\n    for i in range(3):\n        d.append(y[i] - x[i])\n        q.append(0.5 if x[i] == 0 else y[i] / x[i])\n        f.append(q[i] % 1 == 0)\n    for i in range(3):\n        j, k = (i + 1) % 3, (i + 2) % 3\n        if x[j] == y[j] and x[k] == y[k]:\n            return 1\n        if x[i] == y[i] and (d[j] == d[k] or (f[j] and eq(q[j], q[k]))):\n            return 1\n    if (d[0] == d[1] and d[0] == d[2]) or (f[0] and eq(q[0], q[1]) and eq(q[0], q[2])):\n        return 1\n    return 2\ndef move(subset, oper, d):\n    res = x.copy()\n    for i in range(3):\n        if subset[i] == \'1\':\n            res[i] = res[i] + d if oper else res[i] * d\n    return res\nfor tc in range(int(input())):\n    x = list(map(int, input().split()))\n    y = list(map(int, input().split()))\n    a = check(x)\n    if a < 2:\n        print(a)\n        continue\n    d, q, f = [], [], []\n    for i in range(3):\n        d.append(y[i] - x[i])\n        q.append(0.5 if x[i] == 0 else y[i] / x[i])\n        f.append(q[i] % 1 == 0)\n    flag = False\n    for subset in subsets:\n        for i in range(3):\n            a = check(move(subset, True, d[i]))\n            if a < 2:\n                print(2)\n                flag = True\n                break\n            if f[i]:\n                a = check(move(subset, False, q[i]))\n                if a < 2:\n                    print(2)\n                    flag = True\n                    break\n        if flag:\n            break\n    if flag:\n        continue\n    for i in range(3):\n        j, k = (i + 1) % 3, (i + 2) % 3\n        if x[j] != 0 and x[k] != 0 and eq((y[j] - d[i]) / x[j], (y[k] - d[i]) / x[k]) and ((y[j] - d[i]) / x[j]) % 1 == 0:\n            print(2)\n            flag = True\n            break\n    if flag:\n        continue\n    if x[0] != x[1] and x[0] != x[2] and eq((y[0] - y[1]) / (x[0] - x[1]), (y[0] - y[2]) / (x[0] - x[2])):\n        print(2)\n        continue\n    print(3)'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 15013