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 = 'for _ in range(int(input())):\n    a, b, c = map(int, input().split())\n    p, q, r = map(int, input().split())\n    zeros = [a, b, c].count(0)\n    d, e, f = p - a, q - b, r - c\n    operations = 0\n    if d == e == f:\n        if d:\n            operations = 1\n        else:\n            operations = 0\n    elif zeros >= 2:\n        if (d == e and f == 0) or (d == e == 0 and f) or (e == f and d == 0) or (e == f == 0 and d) or (f == d and e == 0) or (f == d == 0 and e):\n            operations = 1\n        elif d == e or e == f or f == d or d == e + f or e == d + f or f == d + e:\n            operations = 2\n    elif zeros == 1:\n        if a == 0:\n            if (d == e and f == 0) or (d == e == 0 and f) or (e == f and d == 0) or (e == f == 0 and d) or (f == d and e == 0) or (f == d == 0 and e) or (d == 0 and q // b == r // c and q % b == 0 and r % c == 0):\n                operations = 1\n            elif d == e or e == f or f == d or (d and q // b == r // c and q % b == 0 and r % c == 0) or d == e + f or e == d + f or f == d + e:\n                operations = 2\n        elif b == 0:\n            if (d == e and f == 0) or (d == e == 0 and f) or (e == f and d == 0) or (e == f == 0 and d) or (f == d and e == 0) or (f == d == 0 and e) or (e == 0 and p // a == r // c and p % a == 0 and r % c == 0):\n                operations = 1\n            elif d == e or e == f or f == d or (e and p // a == r // c and p % a == 0 and r % c == 0) or d == e + f or e == d + f or f == d + e:\n                operations = 2\n        else:\n            if (d == e and f == 0) or (d == e == 0 and f) or (e == f and d == 0) or (e == f == 0 and d) or (f == d and e == 0) or (f == d == 0 and e) or (f == 0 and p // a == q // b and p % a == 0 and q % b == 0):\n                operations = 1\n            elif d == e or e == f or f == d or (f and p // a == q // b and p % a == 0 and q % b == 0) or d == e + f or e == d + f or f == d + e:\n                operations = 2\n    else:\n        x, y, z = p // a, q // b, r // c\n        if (d == e and f == 0) or (d == e == 0 and f) or (e == f and d == 0) or (e == f == 0 and d) or (f == d and e == 0) or (f == d == 0 and e) or (x == y == z and p % a == 0 and q % b == 0 and r % c == 0) or (d == 0 and y == z and q % b == 0 and r % c == 0) or (e == 0 and x == z and p % a == 0 and r % c == 0) or (f == 0 and x == y and p % a == 0 and q % b == 0):\n            operations = 1\n        elif d == e or e == f or f == d or (f and x == y and p % a == 0 and q % b == 0) or (d and y == z and q % b == 0 and r % c == 0) or (e and x == z and p % a == 0 and r % c == 0) or (d == 0 and e != f and e and f) or (e == 0 and d != f and d and f) or (f == 0 and d != e and d and e) or d == e + f or e == d + f or f == d + e or (p % a == 0 and q % b == 0 and r % c == 0 and (x * y == z or y * z == x or z * x == y)):\n            operations = 2\n    if operations == 0:\n        if d:\n            operations += 1\n        if e:\n            operations += 1\n        if f:\n            operations += 1\n    if operations == 3:\n        try:\n            u, v, w = (q * a - p * b) // (p - q), (r * b - q * c) // (q - r), (p * c - r * a) // (r - p)\n            if u == v == w and (q * a - p * b) % (p - q) == 0 and (r * b - q * c) % (q - r) == 0 and (p * c - r * a) % (r - p) == 0 and p // (a + u) == q // (b + u) == r // (c + u) and p % (a + u) == 0 and q % (b + u) == 0 and r % (c + u) == 0:\n                operations = 2\n        except:\n            pass\n        if operations == 3:\n            try:\n                x = p // a\n                if p % a == 0 and ((q % x == 0 and c + (q // x) - b == r) or (r % x == 0 and b + (r // x) - c == q)):\n                    operations = 2\n            except:\n                pass\n            if operations == 3:\n                try:\n                    x = q // b\n                    if q % b == 0 and ((p % x == 0 and c + (p // x) - a == r) or (r % x == 0 and a + (r // x) - c == p)):\n                        operations = 2\n                except:\n                    pass\n                if operations == 3:\n                    try:\n                        x = r // c\n                        if r % c == 0 and ((p % x == 0 and b + (p // x) - a == q) or (q % x == 0 and a + (q // x) - b == p)):\n                            operations = 2\n                    except:\n                        pass\n                    if operations == 3:\n                        try:\n                            if (q * a - p * b) % (p - q) == 0:\n                                u, x = (q * a - p * b) // (p - q), p // (a + u)\n                                if x == q // (b + u) and p % (a + u) == 0 and q % (b + u) == 0 and (c * x == r or c + u == r):\n                                    operations = 2\n                        except:\n                            pass\n                        if operations == 3:\n                            try:\n                                if (r * b - q * c) % (q - r) == 0:\n                                    v, x = (r * b - q * c) // (q - r), q // (b + v)\n                                    if x == r // (c + v) and q % (b + v) == 0 and r % (c + v) == 0 and (a * x == p or a + v == p):\n                                        operations = 2\n                            except:\n                                pass\n                            if operations == 3:\n                                try:\n                                    if (p * c - r * a) % (r - p) == 0:\n                                        w, x = (p * c - r * a) // (r - p), r // (c + w)\n                                        if x == p // (a + w) and r % (c + w) == 0 and p % (a + w) == 0 and (b * x == q or b + w == q):\n                                            operations = 2\n                                except:\n                                    pass\n                                if operations == 3:\n                                    try:\n                                        x, y, z = (p - q) // (a - b), (q - r) // (b - c), (r - p) // (c - a)\n                                        if x == y == z and (p - q) % (a - b) == 0 and (q - r) % (b - c) == 0 and (r - p) % (c - a) == 0 and p - a * x == q - b * y == r - c * z:\n                                            operations = 2\n                                    except:\n                                        pass\n                                    if operations == 3:\n                                        try:\n                                            x = p // a\n                                            if p % a == 0 and (b * x + r - c == q or c * x + q - b == r):\n                                                operations = 2\n                                        except:\n                                            pass\n                                        if operations == 3:\n                                            try:\n                                                x = q // b\n                                                if q % b == 0 and (a * x + r - c == p or c * x + p - a == r):\n                                                    operations = 2\n                                            except:\n                                                pass\n                                            if operations == 3:\n                                                try:\n                                                    x = r // c\n                                                    if r % c == 0 and (a * x + q - b == p or b * x + p - a == q):\n                                                        operations = 2\n                                                except:\n                                                    pass\n                                                if operations == 3:\n                                                    try:\n                                                        x = (p - q) // (a - b)\n                                                        if (p - q) % (a - b) == 0 and p - a * x == q - b * x and (c + p - a * x == r or c * x == r):\n                                                            operations = 2\n                                                    except:\n                                                        pass\n                                                    if operations == 3:\n                                                        try:\n                                                            y = (q - r) // (b - c)\n                                                            if (q - r) % (b - c) == 0 and q - b * y == r - c * y and (a + q - b * y == p or a * y == p):\n                                                                operations = 2\n                                                        except:\n                                                            pass\n                                                        if operations == 3:\n                                                            try:\n                                                                z = (r - p) // (c - a)\n                                                                if (r - p) % (c - a) == 0 and r - c * z == p - a * z and (b + r - c * z == q or b * z == q):\n                                                                    operations = 2\n                                                            except:\n                                                                pass\n    print(operations)'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 18517