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$.

Source: codechef | Difficulty: HARD
Tags: Mathematics


Solutions:
def case1(p, q, r, a, b, c):
	for i in range(2):
		if i == 0:
			d = a - p
			if (q + d == b or q == b) and (r + d == c or r == c):
				return 1
		elif i == 1 and p != 0 and (a % p == 0):
			d = a // p
			if (q * d == b or q == b) and (r * d == c or r == c):
				return 1
	return 0

def case2(p, q, r, a, b, c):
	if p == a:
		if b - q != c - r:
			if q != 0 and r != 0:
				diff1 = b / q
				diff2 = c / r
				if int(diff1) == diff1 and int(diff2) == diff2:
					if diff1 != diff2:
						return 2
	x = a - p
	y = b - q
	z = c - r
	new = [x, y, z]
	if len(set(new)) == 2 and 0 not in set(new):
		return 2
	if len(set(new)) == 3 and 0 in new:
		return 2
	if p != 0 and q != 0 and (r != 0) and (r != c):
		r1 = a / p
		r2 = b / q
		r3 = c / r
		if int(r1) == r1 and int(r2) == r2 and (r1 == r2):
			if int(r3) == r3 and r3 != r1:
				return 2
	diff1 = a - p
	diff2 = b - q
	diff3 = c - r
	if diff1 == diff2 and diff1 != diff3:
		return 2
	d1 = a - p
	d2 = b - q
	d3 = c - r
	if d1 == d2 or d2 == d3 or d1 == d3 or (d1 + d2 == d3) or (d1 + d3 == d2) or (d2 + d3 == d1):
		return 2
	if d1 == 0 and d2 != d3 and (d2 != 0) and (d3 != 0) or (d2 == 0 and d1 != d3 and (d1 != 0) and (d3 != 0)) or (d3 == 0 and d2 != d1 and (d1 != 0) and (d2 != 0)):
		return 2
	elif d1 != d2 and d2 == d3 or (d1 != d3 and d2 == d1) or (d3 != d2 and d1 == d3):
		return 2
	elif (p != 0 and a % p == 0) and (q != 0 and b % q == 0) and (r != 0 and c % r == 0):
		f1 = a // p
		f2 = b // q
		f3 = c // r
		if f1 == f2 or f2 == f3 or f3 == f1:
			return 2
		elif f3 == f1 * f2 or f2 == f1 * f3 or f1 == f2 * f3:
			return 2
	if a - b != 0:
		x = (p * b - q * a) / (a - b)
		if p + x != 0:
			y = a / (p + x)
			if x == int(x) and y == int(y):
				if (r + x) * y == c or r + x == c or r * y == c:
					return 2
	if q != 0:
		y = b / q
		if y != 0:
			x = a / y - p
			if x == int(x) and y == int(y):
				if (r + x) * y == c or r + x == c or r * y == c or (r == c):
					return 2
	x = b - q
	if p + x != 0:
		y = a / (p + x)
		if x == int(x) and y == int(y):
			if (r + x) * y == c or r + x == c or r * y == c or (r == c):
				return 2
	if p - q != 0:
		y = (p * b - a * q) / (p - q)
		if p != 0:
			x = (a - y) / p
			if x == int(x) and y == int(y):
				if r * x + y == c or r + y == c or r * x == c:
					return 2
	if q != 0:
		x = b / q
		y = a - p * x
		if x == int(x) and y == int(y):
			if r * x + y == c or r + y == c or r * x == c or (r == c):
				return 2
	y = b - q
	if p != 0:
		x = (a - y) / p
		if x == int(x) and y == int(y):
			if r * x + y == c or r + y == c or r * x == c or (r == c):
				return 2
	return 0
for _ in range(int(input())):
	start = list(map(int, input().split()))
	stop = list(map(int, input().split()))
	if start == stop:
		print(0)
		continue
	p = start[0]
	q = start[1]
	r = start[2]
	a = stop[0]
	b = stop[1]
	c = stop[2]
	out = case1(p, q, r, a, b, c)
	if out == 1:
		print(1)
		continue
	out = case1(p, r, q, a, c, b)
	if out == 1:
		print(1)
		continue
	out = case1(q, p, r, b, a, c)
	if out == 1:
		print(1)
		continue
	out = case1(q, r, p, b, c, a)
	if out == 1:
		print(1)
		continue
	out = case1(r, p, q, c, a, b)
	if out == 1:
		print(1)
		continue
	out = case1(r, q, p, c, b, a)
	if out == 1:
		print(1)
		continue
	x = a - p
	y = b - q
	z = c - r
	new = [x, y, z]
	if len(set(new)) == 2:
		print(2)
		continue
	if len(set(new)) == 3 and 0 in new:
		print(2)
		continue
	out = case2(p, q, r, a, b, c)
	if out == 2:
		print(2)
		continue
	out = case2(p, r, q, a, c, b)
	if out == 2:
		print(2)
		continue
	out = case2(q, p, r, b, a, c)
	if out == 2:
		print(2)
		continue
	out = case2(q, r, p, b, c, a)
	if out == 2:
		print(2)
		continue
	out = case2(r, p, q, c, a, b)
	if out == 2:
		print(2)
		continue
	out = case2(r, q, p, c, b, a)
	if out == 2:
		print(2)
		continue
	print(3)


def func2(t1, t2, t3, t4):
	if t1 == t3 and t2 == t4:
		return 0
	elif t1 == t3 and t2 != t4:
		return 1
	elif t1 != t3 and t2 == t4:
		return 1
	elif t1 == t2:
		if t3 == t4:
			return 1
		else:
			return 2
	elif t3 == t4:
		if t3 == 0:
			return 1
		else:
			return 2
	elif t1 != 0 and t2 != 0:
		if t3 - t1 == t4 - t2:
			return 1
		elif t1 * t4 == t2 * t3 and t3 % t1 == 0 and (t4 % t2 == 0):
			return 1
		else:
			return 2
	elif t1 == 0 and t4 == t2 + t3:
		return 1
	elif t2 == 0 and t3 == t1 + t4:
		return 1
	return 2

def func4(a, b, c, p, q, r, l1, l2):
	lis = [func2(a, b, p, q), func2(a, c, p, r), func2(b, c, q, r)]
	if len(set(lis)) == 1 and lis[0] == 2:
		for i in range(3):
			k1 = l2[i] - l1[i]
			temp = [func2(l1[i - 1], l1[i - 2], l2[i - 1], l2[i - 2]), func2(l1[i - 1] + k1, l1[i - 2], l2[i - 1], l2[i - 2]), func2(l1[i - 1], l1[i - 2] + k1, l2[i - 1], l2[i - 2]), func2(l1[i - 1] + k1, l1[i - 2] + k1, l2[i - 1], l2[i - 2]), func2(l1[i - 1], l1[i - 2], l2[i - 1] - k1, l2[i - 2] - k1), func2(l1[i - 1], l1[i - 2], l2[i - 1] - k1, l2[i - 2]), func2(l1[i - 1], l1[i - 2], l2[i - 1], l2[i - 2] - k1)]
			ans = min(temp)
			if ans == 1:
				return 2
			if l1[i] != 0:
				if l2[i] % l1[i] == 0:
					k1 = l2[i] // l1[i]
					if k1 != 0:
						temp = [func2(l1[i - 1], l1[i - 2], l2[i - 1], l2[i - 2]), func2(l1[i - 1] * k1, l1[i - 2], l2[i - 1], l2[i - 2]), func2(l1[i - 1], l1[i - 2] * k1, l2[i - 1], l2[i - 2]), func2(l1[i - 1] * k1, l1[i - 2] * k1, l2[i - 1], l2[i - 2]), func2(l1[i - 1], l1[i - 2], l2[i - 1] / k1, l2[i - 2] / k1), func2(l1[i - 1], l1[i - 2], l2[i - 1] / k1, l2[i - 2]), func2(l1[i - 1], l1[i - 2], l2[i - 1], l2[i - 2] / k1)]
						ans = min(temp)
						if ans == 1:
							return 2
					else:
						k1 = 0
						temp = [func2(l1[i - 1], l1[i - 2], l2[i - 1], l2[i - 2]), func2(l1[i - 1] * k1, l1[i - 2], l2[i - 1], l2[i - 2]), func2(l1[i - 1], l1[i - 2] * k1, l2[i - 1], l2[i - 2]), func2(l1[i - 1] * k1, l1[i - 2] * k1, l2[i - 1], l2[i - 2])]
						ans = min(temp)
						if ans == 1:
							return 2
		for i in range(3):
			if l1[i] != l1[i - 1]:
				k1 = l2[i] - l2[i - 1]
				k1 /= l1[i] - l1[i - 1]
				if k1 == int(k1):
					k2 = l2[i] - l1[i] * k1
					if l2[i - 2] == l1[i - 2] * k1 + k2:
						return 2
			else:
				k1 = l2[i] - l1[i]
				lis = [func2(l1[i - 1], l1[i - 2], l2[i - 1], l2[i - 2]), func2(l1[i - 1] + k1, l1[i - 2], l2[i - 1], l2[i - 2]), func2(l1[i - 1], l1[i - 2] + k1, l2[i - 1], l2[i - 2]), func2(l1[i - 1] + k1, l1[i - 2] + k1, l2[i - 1], l2[i - 2]), func2(l1[i - 1], l1[i - 2], l2[i - 1] - k1, l2[i - 2] - k1), func2(l1[i - 1], l1[i - 2], l2[i - 1] - k1, l2[i - 2]), func2(l1[i - 1], l1[i - 2], l2[i - 1], l2[i - 2] - k1)]
				ans = min(lis)
				if ans == 1:
					return 2
				k1 = l2[i - 1] - l1[i - 1]
				lis = [func2(l1[i], l1[i - 2], l2[i], l2[i - 2]), func2(l1[i] + k1, l1[i - 2], l2[i], l2[i - 2]), func2(l1[i], l1[i - 2] + k1, l2[i], l2[i - 2]), func2(l1[i] + k1, l1[i - 2] + k1, l2[i], l2[i - 2]), func2(l1[i], l1[i - 2], l2[i] - k1, l2[i - 2] - k1), func2(l1[i], l1[i - 2], l2[i] - k1, l2[i - 2]), func2(l1[i], l1[i - 2], l2[i], l2[i - 2] - k1)]
				ans = min(lis)
				if ans == 1:
					return 2
		return 3
	ans = max(lis)
	return ans
for _ in range(int(input())):
	lis1 = list(map(int, input().split()))
	lis2 = list(map(int, input().split()))
	(a, b, c) = (lis1[0], lis1[1], lis1[2])
	(p, q, r) = (lis2[0], lis2[1], lis2[2])
	ans1 = func4(a, b, c, p, q, r, lis1, lis2)
	print(ans1)


def is_integer_num(n):
	if isinstance(n, int):
		return True
	if isinstance(n, float):
		return n.is_integer()
	return False
for k in range(int(input())):
	l = [int(p) for p in input().split()]
	d = [int(p) for p in input().split()]
	(a, c, q, b, p, r) = (l[0], l[1], l[2], d[0], d[1], d[2])
	if l == d:
		print(0)
		continue
	if l[0] != 0 and l[1] != 0 and (l[2] != 0):
		if d[0] == l[0] and d[1] == l[1] or (d[0] == l[0] and d[2] == l[2]) or (d[2] == l[2] and d[1] == l[1]):
			print(1)
		elif d[0] == l[0] or d[1] == l[1] or d[2] == l[2]:
			if d[0] == l[0]:
				if d[2] + l[1] == d[1] + l[2] or (d[1] / l[1] == d[2] / l[2] and is_integer_num(d[1] / l[1])):
					print(1)
				else:
					print(2)
			elif d[1] == l[1]:
				if d[2] + l[0] == d[0] + l[2] or (d[0] * l[2] == d[2] * l[0] and is_integer_num(d[0] / l[0])):
					print(1)
				else:
					print(2)
			elif d[2] == l[2]:
				if d[0] + l[1] == d[1] + l[0] or (d[0] * l[1] == d[1] * l[0] and is_integer_num(d[0] / l[0])):
					print(1)
				else:
					print(2)
		elif d[0] + l[1] == d[1] + l[0] and d[0] + l[2] == d[2] + l[0] or ((d[0] * l[1] == d[1] * l[0] and is_integer_num(d[0] / l[0])) and (d[0] * l[2] == d[2] * l[0] and is_integer_num(d[0] / l[0]))):
			print(1)
		elif (d[0] + l[1] == d[1] + l[0] or d[0] + l[2] == d[2] + l[0] or d[1] + l[2] == d[2] + l[1]) or (d[0] * l[1] == d[1] * l[0] and is_integer_num(d[0] / l[0]) or (d[0] * l[2] == d[2] * l[0] and is_integer_num(d[0] / l[0])) or (d[1] * l[2] == d[2] * l[1] and is_integer_num(d[1] / l[1]))):
			print(2)
		else:
			m = [[l[0], d[0], l[1], d[1], l[2], d[2]], [l[0], d[0], l[2], d[2], l[1], d[1]], [l[1], d[1], l[0], d[0], l[2], d[2]], [l[1], d[1], l[2], d[2], l[0], d[0]], [l[2], d[2], l[1], d[1], l[0], d[0]], [l[2], d[2], l[0], d[0], l[1], d[1]]]
			x = 0
			for (a, b, c, p, q, r) in m:
				flag = 0
				flag1 = 0
				if a != c:
					multiply = (b - p) / (a - c)
					if b != p:
						plus1 = b / multiply - a
					else:
						plus1 = -1
						flag1 = 1
					plus2 = b - a * multiply
				else:
					multiply = -1
					plus1 = -1
					plus2 = -1
					flag = 1
				if (c + (b - a)) * r == q * p and is_integer_num(r / q) or (c * r + q * (b - a) == q * p and is_integer_num(r / q)) or (c * b * r == a * q * p and is_integer_num(r / q) and is_integer_num(b / a)) or (c + (b - a) + (q - r) == p):
					x = 1
					print(2)
					break
				elif (q + plus1 == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus1) or is_integer_num(plus2)))) and flag == 0:
					x = 1
					print(2)
					break
				elif ((q + plus1) * multiply == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q * multiply + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus1) or is_integer_num(plus2)))) and flag == 0:
					x = 1
					print(2)
					break
			if x == 0:
				print(3)
	elif l[0] == 0 and l[1] == 0 and (l[2] == 0):
		if d[0] == l[0] and d[1] == l[1] or (d[0] == l[0] and d[2] == l[2]) or (d[2] == l[2] and d[1] == l[1]):
			print(1)
		elif d[0] == l[0] or d[1] == l[1] or d[2] == l[2]:
			if d[0] == l[0]:
				if d[2] + l[1] == d[1] + l[2] or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0)):
					print(1)
				else:
					print(2)
			elif d[1] == l[1]:
				if d[2] + l[0] == d[0] + l[2] or (d[0] * l[2] == d[2] * l[0] and (l[2] != 0 or l[0] != 0)):
					print(1)
				else:
					print(2)
			elif d[2] == l[2]:
				if d[0] + l[1] == d[1] + l[0] or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0)):
					print(1)
				else:
					print(2)
		elif d[0] + l[1] == d[1] + l[0] and d[0] + l[2] == d[2] + l[0] or ((d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0)) and (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0))):
			print(1)
		elif (d[0] + l[1] == d[1] + l[0] or d[0] + l[2] == d[2] + l[0] or d[1] + l[2] == d[2] + l[1]) or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) or (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0)) or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0))):
			print(2)
		elif a + (p - c) + (r - q) == b or c + (b - a) + (r - q) == p or q + (p - c) + (b - a) == r:
			print(2)
		else:
			m = [[l[0], d[0], l[1], d[1], l[2], d[2]], [l[0], d[0], l[2], d[2], l[1], d[1]], [l[1], d[1], l[0], d[0], l[2], d[2]], [l[1], d[1], l[2], d[2], l[0], d[0]], [l[2], d[2], l[1], d[1], l[0], d[0]], [l[2], d[2], l[0], d[0], l[1], d[1]]]
			x = 0
			for (a, b, c, p, q, r) in m:
				flag = 0
				flag1 = 0
				if a != c:
					multiply = (b - p) / (a - c)
					if b != p:
						plus1 = b / multiply - a
					else:
						plus1 = -1
						flag1 = 1
					plus2 = b - a * multiply
				else:
					multiply = -1
					plus1 = -1
					plus2 = -1
					flag = 1
				if (q + plus1 == r and is_integer_num(plus1) and (flag1 == 0) or (q + plus2 == r and is_integer_num(plus2)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus1) or is_integer_num(plus2)))) and flag == 0:
					x = 1
					print(2)
					break
				elif ((q + plus1) * multiply == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q * multiply + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus1) or is_integer_num(plus2)))) and flag == 0:
					x = 1
					print(2)
					break
			if x == 0:
				print(3)
	elif l[1] == 0 and l[2] == 0:
		if d[0] == l[0] and d[1] == l[1] or (d[0] == l[0] and d[2] == l[2]) or (d[2] == l[2] and d[1] == l[1]):
			print(1)
		elif d[0] == l[0] or d[1] == l[1] or d[2] == l[2]:
			if d[0] == l[0]:
				if d[2] + l[1] == d[1] + l[2] or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0)):
					print(1)
				else:
					print(2)
			elif d[1] == l[1]:
				if d[2] + l[0] == d[0] + l[2] or (d[0] * l[2] == d[2] * l[0] and (l[2] != 0 or l[0] != 0) and is_integer_num(d[0] / l[0])):
					print(1)
				else:
					print(2)
			elif d[2] == l[2]:
				if d[0] + l[1] == d[1] + l[0] or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[0] / l[0])):
					print(1)
				else:
					print(2)
		elif d[0] + l[1] == d[1] + l[0] and d[0] + l[2] == d[2] + l[0] or ((d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[0] / l[0])) and (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0) and is_integer_num(d[0] / l[0]))):
			print(1)
		elif (d[0] + l[1] == d[1] + l[0] or d[0] + l[2] == d[2] + l[0] or d[1] + l[2] == d[2] + l[1]) or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[0] / l[0]) or (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0) and is_integer_num(d[0] / l[0])) or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0))):
			print(2)
		elif (c + (r - q)) * (b / a) == p and is_integer_num(b / a) or ((q + (p - c)) * (b / a) == r and is_integer_num(b / a)) or (c * (b / a) + (r - q) == p and is_integer_num(b / a)) or (q * (b / a) + (p - c) == r and is_integer_num(b / a)) or (a + (p - c) + (r - q) == b) or (c + (b - a) + (r - q) == p) or (q + (p - c) + (b - a) == r):
			print(2)
		else:
			m = [[l[0], d[0], l[1], d[1], l[2], d[2]], [l[0], d[0], l[2], d[2], l[1], d[1]], [l[1], d[1], l[0], d[0], l[2], d[2]], [l[1], d[1], l[2], d[2], l[0], d[0]], [l[2], d[2], l[1], d[1], l[0], d[0]], [l[2], d[2], l[0], d[0], l[1], d[1]]]
			x = 0
			for (a, b, c, p, q, r) in m:
				flag = 0
				flag1 = 0
				if a != c:
					multiply = (b - p) / (a - c)
					if b != p:
						plus1 = b / multiply - a
					else:
						plus1 = -1
						flag1 = 1
					plus2 = b - a * multiply
				else:
					multiply = -1
					plus1 = -1
					plus2 = -1
					flag = 1
				if (q + plus1 == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus2) or is_integer_num(plus1)))) and flag == 0:
					x = 1
					print(2)
					break
				elif ((q + plus1) * multiply == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q * multiply + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus1) or is_integer_num(plus2)))) and flag == 0:
					x = 1
					print(2)
					break
			if x == 0:
				print(3)
	elif l[0] == 0 and l[1] == 0:
		if d[0] == l[0] and d[1] == l[1] or (d[0] == l[0] and d[2] == l[2]) or (d[2] == l[2] and d[1] == l[1]):
			print(1)
		elif d[0] == l[0] or d[1] == l[1] or d[2] == l[2]:
			if d[0] == l[0]:
				if d[2] + l[1] == d[1] + l[2] or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0) and is_integer_num(d[2] / l[2])):
					print(1)
				else:
					print(2)
			elif d[1] == l[1]:
				if d[2] + l[0] == d[0] + l[2] or (d[0] * l[2] == d[2] * l[0] and (l[2] != 0 or l[0] != 0) and is_integer_num(d[2] / l[2])):
					print(1)
				else:
					print(2)
			elif d[2] == l[2]:
				if d[0] + l[1] == d[1] + l[0] or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0)):
					print(1)
				else:
					print(2)
		elif d[0] + l[1] == d[1] + l[0] and d[0] + l[2] == d[2] + l[0] or ((d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0)) and (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0) and is_integer_num(d[2] / l[2]))):
			print(1)
		elif (d[0] + l[1] == d[1] + l[0] or d[0] + l[2] == d[2] + l[0] or d[1] + l[2] == d[2] + l[1]) or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) or (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0) and is_integer_num(d[2] / l[2])) or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0) and is_integer_num(d[2] / l[2]))):
			print(2)
		elif (c + (b - a)) * (r / q) == p and is_integer_num(r / q) or ((a + (p - c)) * (r / q) == b and is_integer_num(r / q)) or (c * (r / q) + (b - a) == p and is_integer_num(r / q)) or (a * (r / q) + (p - c) == b and is_integer_num(r / q)) or (a + (p - c) + (r - q) == b) or (c + (b - a) + (r - q) == p) or (q + (p - c) + (b - a) == r):
			print(2)
		else:
			m = [[l[0], d[0], l[1], d[1], l[2], d[2]], [l[0], d[0], l[2], d[2], l[1], d[1]], [l[1], d[1], l[0], d[0], l[2], d[2]], [l[1], d[1], l[2], d[2], l[0], d[0]], [l[2], d[2], l[1], d[1], l[0], d[0]], [l[2], d[2], l[0], d[0], l[1], d[1]]]
			x = 0
			for (a, b, c, p, q, r) in m:
				flag = 0
				flag1 = 0
				if a != c:
					multiply = (b - p) / (a - c)
					if b != p:
						plus1 = b / multiply - a
					else:
						plus1 = -1
						flag1 = 1
					plus2 = b - a * multiply
				else:
					multiply = -1
					plus1 = -1
					plus2 = -1
					flag = 1
				if (q + plus1 == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus2) or is_integer_num(plus1)))) and flag == 0:
					x = 1
					print(2)
					break
				elif ((q + plus1) * multiply == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q * multiply + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus1) or is_integer_num(plus2)))) and flag == 0:
					x = 1
					print(2)
					break
			if x == 0:
				print(3)
	elif l[0] == 0 and l[2] == 0:
		if d[0] == l[0] and d[1] == l[1] or (d[0] == l[0] and d[2] == l[2]) or (d[2] == l[2] and d[1] == l[1]):
			print(1)
		elif d[0] == l[0] or d[1] == l[1] or d[2] == l[2]:
			if d[0] == l[0]:
				if d[2] + l[1] == d[1] + l[2] or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0) and is_integer_num(d[1] / l[1])):
					print(1)
				else:
					print(2)
			elif d[1] == l[1]:
				if d[2] + l[0] == d[0] + l[2] or (d[0] * l[2] == d[2] * l[0] and (l[2] != 0 or l[0] != 0)):
					print(1)
				else:
					print(2)
			elif d[2] == l[2]:
				if d[0] + l[1] == d[1] + l[0] or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[1] / l[1])):
					print(1)
				else:
					print(2)
		elif d[0] + l[1] == d[1] + l[0] and d[0] + l[2] == d[2] + l[0] or ((d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[1] / l[1])) and (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0))):
			print(1)
		elif (d[0] + l[1] == d[1] + l[0] or d[0] + l[2] == d[2] + l[0] or d[1] + l[2] == d[2] + l[1]) or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[1] / l[1]) or (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0)) or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0) and is_integer_num(d[1] / l[1]))):
			print(2)
		elif (q + (b - a)) * (p / c) == r and is_integer_num(p / c) or ((a + (r - q)) * (p / c) == b and is_integer_num(p / c)) or (q * (p / c) + (b - a) == r and is_integer_num(p / c)) or (a * (p / c) + (r - q) == b and is_integer_num(p / c)) or (a + (p - c) + (r - q) == b) or (c + (b - a) + (r - q) == p) or (q + (p - c) + (b - a) == r):
			print(2)
		else:
			m = [[l[0], d[0], l[1], d[1], l[2], d[2]], [l[0], d[0], l[2], d[2], l[1], d[1]], [l[1], d[1], l[0], d[0], l[2], d[2]], [l[1], d[1], l[2], d[2], l[0], d[0]], [l[2], d[2], l[1], d[1], l[0], d[0]], [l[2], d[2], l[0], d[0], l[1], d[1]]]
			x = 0
			for (a, b, c, p, q, r) in m:
				flag = 0
				flag1 = 0
				if a != c:
					multiply = (b - p) / (a - c)
					if b != p:
						plus1 = b / multiply - a
					else:
						plus1 = -1
						flag1 = 1
					plus2 = b - a * multiply
				else:
					multiply = -1
					plus1 = -1
					plus2 = -1
					flag = 1
				if (q + plus1 == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus2) or is_integer_num(plus1)))) and flag == 0:
					x = 1
					print(2)
					break
				elif ((q + plus1) * multiply == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q * multiply + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus1) or is_integer_num(plus2)))) and flag == 0:
					x = 1
					print(2)
					break
			if x == 0:
				print(3)
	elif l[0] == 0:
		if d[0] == l[0] and d[1] == l[1] or (d[0] == l[0] and d[2] == l[2]) or (d[2] == l[2] and d[1] == l[1]):
			print(1)
		elif d[0] == l[0] or d[1] == l[1] or d[2] == l[2]:
			if d[0] == l[0]:
				if d[2] + l[1] == d[1] + l[2] or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0) and is_integer_num(d[1] / l[1])):
					print(1)
				else:
					print(2)
			elif d[1] == l[1]:
				if d[2] + l[0] == d[0] + l[2] or (d[0] * l[2] == d[2] * l[0] and (l[2] != 0 or l[0] != 0) and is_integer_num(d[2] / l[2])):
					print(1)
				else:
					print(2)
			elif d[2] == l[2]:
				if d[0] + l[1] == d[1] + l[0] or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[1] / l[1])):
					print(1)
				else:
					print(2)
		elif d[0] + l[1] == d[1] + l[0] and d[0] + l[2] == d[2] + l[0] or ((d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[1] / l[1])) and (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0) and is_integer_num(d[2] / l[2]))):
			print(1)
		elif (d[0] + l[1] == d[1] + l[0] or d[0] + l[2] == d[2] + l[0] or d[1] + l[2] == d[2] + l[1]) or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[1] / l[1]) or (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0) and is_integer_num(d[2] / l[2])) or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0) and is_integer_num(d[1] / l[1]))):
			print(2)
		elif (c + (b - a)) * (r / q) == p and is_integer_num(r / q) or ((q + (b - a)) * (p / c) == r and is_integer_num(p / c)) or ((a + (p - c)) * (r / q) == b and is_integer_num(r / q)) or ((a + (r - q)) * (p / c) == b and is_integer_num(p / c)) or (c * (r / q) + (b - a) == p and is_integer_num(r / q)) or (q * (p / c) + (b - a) == r and is_integer_num(p / c)) or (a * (r / q) + (p - c) == b and is_integer_num(r / q)) or (a * (p / c) + (r - q) == b and is_integer_num(p / c)) or (a * (p / c) * (r / q) == b and is_integer_num(p / c) and is_integer_num(r / q)) or (a + (p - c) + (r - q) == b) or (c + (b - a) + (r - q) == p) or (q + (p - c) + (b - a) == r):
			print(2)
		else:
			m = [[l[0], d[0], l[1], d[1], l[2], d[2]], [l[0], d[0], l[2], d[2], l[1], d[1]], [l[1], d[1], l[0], d[0], l[2], d[2]], [l[1], d[1], l[2], d[2], l[0], d[0]], [l[2], d[2], l[1], d[1], l[0], d[0]], [l[2], d[2], l[0], d[0], l[1], d[1]]]
			x = 0
			for (a, b, c, p, q, r) in m:
				flag = 0
				flag1 = 0
				if a != c:
					multiply = (b - p) / (a - c)
					if b != p:
						plus1 = b / multiply - a
					else:
						plus1 = -1
						flag1 = 1
					plus2 = b - a * multiply
				else:
					multiply = -1
					plus1 = -1
					plus2 = -1
					flag = 1
				if (q + plus1 == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus2) or is_integer_num(plus1)))) and flag == 0:
					x = 1
					print(2)
					break
				elif ((q + plus1) * multiply == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q * multiply + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus1) or is_integer_num(plus2)))) and flag == 0:
					x = 1
					print(2)
					break
			if x == 0:
				print(3)
	elif l[1] == 0:
		if d[0] == l[0] and d[1] == l[1] or (d[0] == l[0] and d[2] == l[2]) or (d[2] == l[2] and d[1] == l[1]):
			print(1)
		elif d[0] == l[0] or d[1] == l[1] or d[2] == l[2]:
			if d[0] == l[0]:
				if d[2] + l[1] == d[1] + l[2] or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0) and is_integer_num(d[2] / l[2])):
					print(1)
				else:
					print(2)
			elif d[1] == l[1]:
				if d[2] + l[0] == d[0] + l[2] or (d[0] * l[2] == d[2] * l[0] and (l[2] != 0 or l[0] != 0) and is_integer_num(d[0] / l[0])):
					print(1)
				else:
					print(2)
			elif d[2] == l[2]:
				if d[0] + l[1] == d[1] + l[0] or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[0] / l[0])):
					print(1)
				else:
					print(2)
		elif d[0] + l[1] == d[1] + l[0] and d[0] + l[2] == d[2] + l[0] or ((d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[0] / l[0])) and (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0) and is_integer_num(d[0] / l[0]))):
			print(1)
		elif (d[0] + l[1] == d[1] + l[0] or d[0] + l[2] == d[2] + l[0] or d[1] + l[2] == d[2] + l[1]) or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[0] / l[0]) or (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0) and is_integer_num(d[0] / l[0])) or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0) and is_integer_num(d[2] / l[2]))):
			print(2)
		elif (c + (b - a)) * (r / q) == p and is_integer_num(r / q) or ((a + (p - c)) * (r / q) == b and is_integer_num(r / q)) or ((c + (r - q)) * (b / a) == p and is_integer_num(b / a)) or ((q + (p - c)) * (b / a) == r and is_integer_num(b / a)) or (c * (r / q) + (b - a) == p and is_integer_num(r / q)) or (a * (r / q) + (p - c) == b and is_integer_num(r / q)) or (c * (b / a) + (r - q) == p and is_integer_num(b / a)) or (q * (b / a) + (p - c) == r and is_integer_num(b / a)) or (c * (b / a) * (r / q) == p and is_integer_num(b / a) and is_integer_num(r / q)) or (a + (p - c) + (r - q) == b) or (c + (b - a) + (r - q) == p) or (q + (p - c) + (b - a) == r):
			print(2)
		else:
			m = [[l[0], d[0], l[1], d[1], l[2], d[2]], [l[0], d[0], l[2], d[2], l[1], d[1]], [l[1], d[1], l[0], d[0], l[2], d[2]], [l[1], d[1], l[2], d[2], l[0], d[0]], [l[2], d[2], l[1], d[1], l[0], d[0]], [l[2], d[2], l[0], d[0], l[1], d[1]]]
			x = 0
			for (a, b, c, p, q, r) in m:
				flag = 0
				flag1 = 0
				if a != c:
					multiply = (b - p) / (a - c)
					if b != p:
						plus1 = b / multiply - a
					else:
						plus1 = -1
						flag1 = 1
					plus2 = b - a * multiply
				else:
					multiply = -1
					plus1 = -1
					plus2 = -1
					flag = 1
				if (q + plus1 == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus2) or is_integer_num(plus1)))) and flag == 0:
					x = 1
					print(2)
					break
				elif ((q + plus1) * multiply == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q * multiply + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus1) or is_integer_num(plus2)))) and flag == 0:
					x = 1
					print(2)
					break
			if x == 0:
				print(3)
	elif l[2] == 0:
		if d[0] == l[0] and d[1] == l[1] or (d[0] == l[0] and d[2] == l[2]) or (d[2] == l[2] and d[1] == l[1]):
			print(1)
		elif d[0] == l[0] or d[1] == l[1] or d[2] == l[2]:
			if d[0] == l[0]:
				if d[2] + l[1] == d[1] + l[2] or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0) and is_integer_num(d[1] / l[1])):
					print(1)
				else:
					print(2)
			elif d[1] == l[1]:
				if d[2] + l[0] == d[0] + l[2] or (d[0] * l[2] == d[2] * l[0] and (l[2] != 0 or l[0] != 0) and is_integer_num(d[0] / l[0])):
					print(1)
				else:
					print(2)
			elif d[2] == l[2]:
				if d[0] + l[1] == d[1] + l[0] or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[0] / l[0])):
					print(1)
				else:
					print(2)
		elif d[0] + l[1] == d[1] + l[0] and d[0] + l[2] == d[2] + l[0] or ((d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[0] / l[0])) and (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0) and is_integer_num(d[0] / l[0]))):
			print(1)
		elif (d[0] + l[1] == d[1] + l[0] or d[0] + l[2] == d[2] + l[0] or d[1] + l[2] == d[2] + l[1]) or (d[0] * l[1] == d[1] * l[0] and (l[0] != 0 or l[1] != 0) and is_integer_num(d[0] / l[0]) or (d[0] * l[2] == d[2] * l[0] and (l[0] != 0 or l[2] != 0) and is_integer_num(d[0] / l[0])) or (d[1] * l[2] == d[2] * l[1] and (l[2] != 0 or l[1] != 0) and is_integer_num(d[1] / l[1]))):
			print(2)
		elif (q + (b - a)) * (p / c) == r and is_integer_num(p / c) or ((a + (r - q)) * (p / c) == b and is_integer_num(p / c)) or ((c + (r - q)) * (b / a) == p and is_integer_num(b / a)) or ((q + (p - c)) * (b / a) == r and is_integer_num(b / a)) or (q * (p / c) + (b - a) == r and is_integer_num(p / c)) or (a * (p / c) + (r - q) == b and is_integer_num(p / c)) or (c * (b / a) + (r - q) == p and is_integer_num(b / a)) or (q * (b / a) + (p - c) == r and is_integer_num(b / a)) or (q * (p / c) * (b / a) == r and is_integer_num(b / a) and is_integer_num(p / c)) or (a + (p - c) + (r - q) == b) or (c + (b - a) + (r - q) == p) or (q + (p - c) + (b - a) == r):
			print(2)
		else:
			m = [[l[0], d[0], l[1], d[1], l[2], d[2]], [l[0], d[0], l[2], d[2], l[1], d[1]], [l[1], d[1], l[0], d[0], l[2], d[2]], [l[1], d[1], l[2], d[2], l[0], d[0]], [l[2], d[2], l[1], d[1], l[0], d[0]], [l[2], d[2], l[0], d[0], l[1], d[1]]]
			x = 0
			for (a, b, c, p, q, r) in m:
				flag = 0
				flag1 = 0
				if a != c:
					multiply = (b - p) / (a - c)
					if b != p:
						plus1 = b / multiply - a
					else:
						plus1 = -1
						flag1 = 1
					plus2 = b - a * multiply
				else:
					multiply = -1
					plus1 = -1
					plus2 = -1
					flag = 1
				if (q + plus1 == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus1) or is_integer_num(plus2)))) and flag == 0:
					x = 1
					print(2)
					break
				elif ((q + plus1) * multiply == r and is_integer_num(plus1) and is_integer_num(multiply) and (flag1 == 0) or (q * multiply + plus2 == r and is_integer_num(plus2) and is_integer_num(multiply)) or (q * multiply == r and is_integer_num(multiply) and (is_integer_num(plus1) or is_integer_num(plus2)))) and flag == 0:
					x = 1
					print(2)
					break
			if x == 0:
				print(3)


def checkpoint1(p, q, r, a, b, c):
	if p == a and b - q == c - r:
		return True
	if q == b and a - p == c - r:
		return True
	if c == r and a - p == b - q:
		return True
	if p == a and q == b:
		return True
	if p == a and c == r:
		return True
	if c == r and b == q:
		return True
	if a - p == b - q and a - p == c - r:
		return True
	if q != 0 and r != 0 and (b % q == 0) and (c % r == 0) and (p == a) and (b / q == c / r):
		return True
	if p != 0 and r != 0 and (a % p == 0) and (c % r == 0) and (q == b) and (a / p == c / r):
		return True
	if p != 0 and q != 0 and (a % p == 0) and (b % q == 0) and (c == r) and (a / p == b / q):
		return True
	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):
		return True
	return False

def checkpoint2(p, q, r, a, b, c):
	x1 = a - p
	y1 = b - q
	z1 = c - r
	if p == a or q == b or r == c:
		return True
	if a - p == b - q or b - q == c - r or c - r == a - p:
		return True
	if p != 0 and q != 0 and (a % p == 0 and b % q == 0) and (a / p == b / q):
		return True
	if p != 0 and r != 0 and (a % p == 0 and c % r == 0) and (a / p == c / r):
		return True
	if q != 0 and r != 0 and (b % q == 0 and c % r == 0) and (b / q == c / r):
		return True
	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):
		return True
	if x1 + y1 == z1 or x1 + z1 == y1 or y1 + z1 == x1:
		return True
	if q + x1 != 0 and r != 0 and (b % (q + x1) == 0) and (c % r == 0) and (b / (q + x1) == c / r):
		return True
	if p != 0 and a % p == 0 and (b - q * a / p == c - r):
		return True
	if q + z1 != 0 and p != 0 and (b % (q + z1) == 0) and (a % p == 0) and (b / (q + z1) == a / p):
		return True
	if r != 0 and c % r == 0 and (b - q * c / r == a - p):
		return True
	if p + y1 != 0 and r != 0 and (a % (p + y1) == 0) and (c % r == 0) and (a / (p + y1) == c / r):
		return True
	if q != 0 and b % q == 0 and (a - p * b / q == c - r):
		return True
	if p + z1 != 0 and q != 0 and (a % (p + z1) == 0) and (b % q == 0) and (a / (p + z1) == b / q):
		return True
	if r != 0 and c % r == 0 and (a - p * c / r == b - q):
		return True
	if r + y1 != 0 and p != 0 and (c % (r + y1) == 0) and (a % p == 0) and (c / (r + y1) == a / p):
		return True
	if q != 0 and b % q == 0 and (c - r * b / q == a - p):
		return True
	if r + x1 != 0 and q != 0 and (c % (r + x1) == 0) and (b % q == 0) and (c / (r + x1) == b / q):
		return True
	if p != 0 and a % p == 0 and (c - r * a / p == b - q):
		return True
	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)):
		return True
	if r != 0 and c % r == 0 and (a - p * c / r == b - q * c / r):
		return True
	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)):
		return True
	if q != 0 and b % q == 0 and (a - p * b / q == c - r * b / q):
		return True
	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)):
		return True
	if p != 0 and a % p == 0 and (b - q * a / p == c - r * a / p):
		return True
	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):
		return True
	if p != 0 and q != 0 and ((a - z1) % p == 0) and ((b - z1) % q == 0) and ((a - z1) / p == (b - z1) / q):
		return True
	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):
		return True
	if p != 0 and r != 0 and ((a - y1) % p == 0) and ((c - y1) % r == 0) and ((a - y1) / p == (c - y1) / r):
		return True
	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):
		return True
	if q != 0 and r != 0 and ((b - x1) % q == 0) and ((c - x1) % r == 0) and ((b - x1) / q == (c - x1) / r):
		return True
	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)):
		return True
	return False
test = int(input())
for _ in range(test):
	(x1, y1, z1) = [int(x) for x in input().split()]
	(a, b, c) = [int(x) for x in input().split()]
	if a == x1 and b == y1 and (c == z1):
		print(0)
	elif checkpoint1(x1, y1, z1, a, b, c):
		print(1)
	elif checkpoint2(x1, y1, z1, a, b, c):
		print(2)
	else:
		print(3)


t = int(input())
while t > 0:
	li1 = [int(i) for i in input().split()]
	li2 = [int(i) for i in input().split()]
	s1 = set()
	s2 = set()
	(val, ans) = (0, 3)
	for i in range(3):
		if li1[i] == li2[i]:
			val += 1
	if val == 3:
		ans = 0
	elif val == 2:
		ans = 1
	else:
		for i in range(3):
			if li2[i] - li1[i] != 0:
				s1.add(li2[i] - li1[i])
			if li1[i] != 0 and li2[i] % li1[i] == 0 and (li2[i] // li1[i] != 1):
				s2.add(li2[i] // li1[i])
		temp = []
		for i in s1:
			for j in range(7):
				temp = [li1[k] for k in range(3)]
				if j == 0:
					temp[0] += i
					temp[1] += i
				elif j == 1:
					temp[0] += i
					temp[2] += i
				elif j == 2:
					temp[1] += i
					temp[2] += i
				elif j == 3:
					temp[0] += i
					temp[1] += i
					temp[2] += i
				elif j == 4:
					temp[0] += i
				elif j == 5:
					temp[1] += i
				elif j == 6:
					temp[2] += i
				a = 0
				for k in range(3):
					if temp[k] == li2[k]:
						a += 1
				if a == 3:
					ans = 1
				if a == 2:
					ans = min(ans, 2)
				s3 = set()
				for k in range(3):
					if temp[k] != 0 and li2[k] % temp[k] == 0 and (li2[k] // temp[k] != 1):
						s3.add(li2[k] // temp[k])
				temp1 = []
				for k in s3:
					for l in range(7):
						temp1 = [temp[m] for m in range(3)]
						if l == 0:
							temp1[0] *= k
							temp1[1] *= k
						elif l == 1:
							temp1[0] *= k
							temp1[2] *= k
						elif l == 2:
							temp1[1] *= k
							temp1[2] *= k
						elif l == 3:
							temp1[0] *= k
							temp1[1] *= k
							temp1[2] *= k
						elif l == 4:
							temp1[0] *= k
						elif l == 5:
							temp1[1] *= k
						elif l == 6:
							temp1[2] *= k
						for m in range(3):
							if li2[m] != temp1[m]:
								break
							if m == 2:
								ans = min(ans, 2)
				s4 = set()
				for k in range(3):
					if li2[k] - temp[k] != 0:
						s4.add(li2[k] - temp[k])
				temp2 = []
				for k in s4:
					for l in range(7):
						temp2 = [temp[m] for m in range(3)]
						if l == 0:
							temp2[0] += k
							temp2[1] += k
						elif l == 1:
							temp2[0] += k
							temp2[2] += k
						elif l == 2:
							temp2[1] += k
							temp2[2] += k
						elif l == 3:
							temp2[0] += k
							temp2[1] += k
							temp2[2] += k
						elif l == 4:
							temp2[0] += k
						elif l == 5:
							temp2[1] += k
						elif l == 6:
							temp2[2] += k
						for m in range(3):
							if li2[m] != temp2[m]:
								break
							if m == 2:
								ans = min(ans, 2)
				s4.clear()
				count = 0
				for k in range(3):
					var = li2[k] - i
					if li1[k] != 0 and var % li1[k] == 0:
						if var // li1[k] != 1:
							s4.add(var // li1[k])
						count += 1
				if len(s4) == 1 and count == 3:
					ans = min(ans, 2)
		if ans == 3 or ans == 2:
			d1 = li2[2] - li2[1]
			d2 = li2[1] - li2[0]
			d3 = li1[2] - li1[1]
			d4 = li1[1] - li1[0]
			d5 = li2[2] - li2[0]
			d6 = li1[2] - li1[0]
			if d3 != 0 and d4 != 0 and (d6 != 0) and (d1 % d3 == 0) and (d2 % d4 == 0) and (d5 % d6 == 0) and (d1 // d3 == d2 // d4) and (d1 // d3 == d5 // d6):
				ans = min(ans, 2)
			for i in s2:
				s3 = set()
				count = 0
				for j in range(3):
					temp[j] = li2[j]
					if i != 0 and temp[j] % i == 0:
						temp[j] //= i
						temp[j] -= li1[j]
						if temp[j] != 0:
							s3.add(temp[j])
						count += 1
				if len(s3) == 1 and count == 3:
					ans = min(ans, 2)
			for i in s2:
				for j in range(7):
					temp = [li1[k] for k in range(3)]
					if j == 0:
						temp[0] *= i
						temp[1] *= i
					elif j == 1:
						temp[0] *= i
						temp[2] *= i
					elif j == 2:
						temp[1] *= i
						temp[2] *= i
					elif j == 3:
						temp[0] *= i
						temp[1] *= i
						temp[2] *= i
					elif j == 4:
						temp[0] *= i
					elif j == 5:
						temp[1] *= i
					elif j == 6:
						temp[2] *= i
					a = 0
					for k in range(3):
						if temp[k] == li2[k]:
							a += 1
					if a == 3:
						ans = 1
					elif a == 2:
						ans = min(ans, 2)
					temp2 = []
					s4 = set()
					for k in range(3):
						if temp[k] != 0 and li2[k] % temp[k] == 0 and (li2[k] // temp[k] != 1):
							s4.add(li2[k] // temp[k])
					temp2 = []
					for k in s4:
						for l in range(7):
							temp2 = [temp[m] for m in range(3)]
							if l == 0:
								temp2[0] *= k
								temp2[1] *= k
							elif l == 1:
								temp2[0] *= k
								temp2[2] *= k
							elif l == 2:
								temp2[1] *= k
								temp2[2] *= k
							elif l == 3:
								temp2[0] *= k
								temp2[1] *= k
								temp2[2] *= k
							elif l == 4:
								temp2[0] *= k
							elif l == 5:
								temp2[1] *= k
							elif l == 6:
								temp2[2] *= k
							for m in range(3):
								if li2[m] != temp2[m]:
									break
								if m == 2:
									ans = min(ans, 2)
					s4.clear()
					for k in range(3):
						var = li2[k] - temp[k]
						if var != 0:
							s4.add(var)
					if len(s4) == 1:
						ans = min(ans, 2)
	print(ans)
	t -= 1


def div1(a1, b1):
	p = 10 ** 10
	if a1 != 0:
		p1 = b1 // a1 if b1 % a1 == 0 else p + 1
	else:
		p1 = 0 if b1 == 0 else p + 1
	return p1

def div2(a2, b2):
	p = 10 ** 10
	if a2 != 0:
		p2 = b2 // a2 if b2 % a2 == 0 else p + 2
	else:
		p2 = 0 if b2 == 0 else p + 2
	return p2

def div3(a3, b3):
	p = 10 ** 10
	if a3 != 0:
		if b3 % a3 == 0:
			p3 = b3 // a3
		else:
			p3 = p + 3
	elif b3 == 0:
		p3 = 0
	else:
		p3 = p + 3
	return p3

def unique(c1, d1, c2, d2, c3, d3):
	pr = 3
	if c1 != 0:
		if d1 % c1 == 0:
			m = d1 // c1
			m1 = d2 - c2
			if c3 + m1 == d3 or c3 * m == d3 or (c3 + m1) * m == d3 or (c3 * m + m1 == d3):
				pr = 2
	if c2 != 0:
		if d2 % c2 == 0:
			m = d2 // c2
			m1 = d1 - c1
			if c3 + m1 == d3 or c3 * m == d3 or (c3 + m1) * m == d3 or (c3 * m + m1 == d3):
				pr = 2
	if c1 != 0 and c2 != 0:
		if d1 % c1 == 0 and d2 % c2 == 0:
			m = d1 // c1
			m1 = d2 // c2
			if c3 * m == d3 or c3 * m1 == d3 or c3 * m * m1 == d3:
				pr = 2
	if c1 != c2:
		if (d1 - d2) % (c1 - c2) == 0:
			m = (d1 - d2) // (c1 - c2)
			m1 = d1 - c1 * m
			if m == 1 or m1 == 0 or c3 + m1 == d3 or (c3 * m == d3) or (c3 * m + m1 == d3):
				pr = 2
	if d1 != d2:
		if (c1 * d2 - c2 * d1) % (d1 - d2) == 0:
			m = (c1 * d2 - c2 * d1) // (d1 - d2)
			if c1 + m != 0:
				if d1 % (c1 + m) == 0:
					m1 = d1 // (c1 + m)
					if m == 0 or m1 == 1 or c3 + m == d3 or (c3 * m1 == d3) or ((c3 + m) * m1 == d3):
						pr = 2
	if d1 == d2 and c1 == c2:
		pr = 2
	if c3 + (d1 - c1) == d3 or c3 + (d2 - c2) == d3 or c3 + (d1 - c1) + (d2 - c2) == d3:
		pr = 2
	return pr
for i in range(int(input())):
	(a1, a2, a3) = map(int, input().split())
	(b1, b2, b3) = map(int, input().split())
	d1 = b1 - a1
	d2 = b2 - a2
	d3 = b3 - a3
	p1 = div1(a1, b1)
	p2 = div2(a2, b2)
	p3 = div3(a3, b3)
	l = [a1, a2, a3]
	l1 = [b1, b2, b3]
	c = 0
	j = 0
	k = 3
	while j < k:
		if l[j] == l1[j]:
			c += 1
			l.remove(l[j])
			l1.remove(l1[j])
			k -= 1
		else:
			j += 1
	if c == 3 or c == 2:
		print(3 - c)
	elif c == 1:
		if l1[0] - l[0] == l1[1] - l[1]:
			print(1)
		elif l[0] != 0 and l[1] != 0:
			print(1) if l1[0] % l[0] == 0 and l1[1] % l[1] == 0 and (l1[0] / l[0] == l1[1] / l[1]) else print(2)
		else:
			print(2)
	elif d1 == d2 and d2 == d3 or (p1 == p2 and p2 == p3):
		print(1)
	else:
		pr1 = 3
		pr2 = 3
		pr3 = 3
		pr1 = unique(a1, b1, a2, b2, a3, b3)
		pr2 = unique(a3, b3, a1, b1, a2, b2)
		pr3 = unique(a2, b2, a3, b3, a1, b1)
		print(min(pr1, pr2, pr3))


def tupp(a, p, b, q, c, r):
	manlo = 3
	if a != b:
		if (p - q) % (a - b) == 0:
			x = (p - q) // (a - b)
			y = p - a * x
			if x == 1 or y == 0 or c + y == r or (c * x == r) or (c * x + y == r):
				manlo = 2
	if p != q:
		if (a * q - b * p) % (p - q) == 0:
			x = (a * q - b * p) // (p - q)
			if a + x != 0:
				if p % (a + x) == 0:
					y = p // (a + x)
					if x == 0 or y == 1 or c + x == r or (c * y == r) or ((c + x) * y == r):
						manlo = 2
	if p == q and a == b:
		manlo = 2
	if c + (p - a) == r or c + (q - b) == r or c + (p - a) + (q - b) == r:
		manlo = 2
	if a != 0 and b != 0:
		if p % a == 0 and q % b == 0:
			x = p // a
			y = q // b
			if c * x == r or c * y == r or c * x * y == r:
				manlo = 2
	if a != 0:
		if p % a == 0:
			x = p // a
			y = q - b
			if c + y == r or c * x == r or (c + y) * x == r or (c * x + y == r):
				manlo = 2
	if b != 0:
		if q % b == 0:
			x = q // b
			y = p - a
			if c + y == r or c * x == r or (c + y) * x == r or (c * x + y == r):
				manlo = 2
	return manlo
for _ in range(int(input())):
	given = list(map(int, input().split()))
	req = list(map(int, input().split()))
	i = 0
	l = 3
	while i < l:
		if given[i] == req[i]:
			given.pop(i)
			req.pop(i)
			l -= 1
		else:
			i += 1
	if len(given) < 2:
		print(len(given))
	elif len(given) == 2:
		manlo = 2
		if given[1] - req[1] == given[0] - req[0]:
			manlo = 1
		if manlo == 2 and given[1] != 0 and (given[0] != 0):
			if req[0] % given[0] == 0 and req[1] % given[1] == 0 and (req[0] / given[0] == req[1] / given[1]):
				manlo = 1
		print(manlo)
	else:
		manlo = 3
		if given[1] - req[1] == given[0] - req[0] and given[1] - req[1] == given[2] - req[2]:
			manlo = 1
		elif given[1] != 0 and given[0] != 0 and (given[2] != 0) and (req[0] % given[0] == 0) and (req[1] % given[1] == 0) and (req[2] % given[2] == 0) and (req[0] / given[0] == req[1] / given[1]) and (req[0] / given[0] == req[2] / given[2]):
			manlo = 1
		else:
			manlo = min(tupp(given[0], req[0], given[1], req[1], given[2], req[2]), manlo)
			manlo = min(tupp(given[1], req[1], given[2], req[2], given[0], req[0]), manlo)
			manlo = min(tupp(given[2], req[2], given[0], req[0], given[1], req[1]), manlo)
		print(manlo)


import sys

def fop(s, end='\n'):
	sys.stdout.write(str(s) + end)

def fip():
	return sys.stdin.readline().strip()
fintinp = lambda : int(fip())

def flistinp(func=int):
	return list(map(func, fip().split()))

def fnsepline(n, func=str):
	return [func(fip()) for _ in range(n)]

def byeqs(pqr, abc):
	(p, q, r) = pqr
	(a, b, c) = abc
	muls = []
	try:
		if p != q:
			m_ = (a - b) // (p - q)
			muls.append(m_)
	except:
		pass
	try:
		if p != r:
			m_ = (a - c) // (p - r)
			muls.append(m_)
	except:
		pass
	try:
		if q != r:
			m_ = (b - c) // (q - r)
			muls.append(m_)
	except:
		pass
	return muls

def recSolver(pqr, abc, ans=0):
	if pqr == abc:
		return ans
	if ans >= 2:
		return 3
	adds = [abc[i] - pqr[i] for i in range(3)]
	muls = [abc[i] // pqr[i] if pqr[i] != 0 else 0 for i in range(3)] + byeqs(pqr, abc)
	f_ans = 3
	for ss in range(8):
		for a in adds:
			pqr_copy = list(pqr)
			for i in [1, 2, 4]:
				if ss & i:
					pqr_copy[i >> 1] += a
			f_ans = min(f_ans, recSolver(pqr_copy, abc, ans + 1))
		for m in muls:
			pqr_copy = list(pqr)
			for i in [1, 2, 4]:
				if ss & i:
					pqr_copy[i >> 1] *= m
			f_ans = min(f_ans, recSolver(pqr_copy, abc, ans + 1))
	return f_ans
for _ in range(fintinp()):
	pqr = flistinp()
	abc = flistinp()
	fop(recSolver(pqr, abc, 0))


from itertools import permutations
oo = 1000000000000
t = int(input())

def check1(e):
	for i in range(len(e) - 1):
		if e[i] != e[i + 1] or e[i] == oo:
			return False
	return True

def check2(e):
	l = len(e)
	for i in range(l):
		if e[i] == e[(i + 1) % l] and e[i] != oo:
			return True
	return False

def check2_2(d, f, a, b):
	perm = permutations([0, 1, 2])
	for i in perm:
		if f[i[0]] != oo and f[i[1]] != oo:
			if b[i[2]] == a[i[2]] * f[i[0]] * f[i[1]]:
				return True
		if a[i[2]] + d[i[0]] + d[i[1]] == b[i[2]]:
			return True
		if f[i[1]] != oo:
			if b[i[2]] == f[i[1]] * (a[i[2]] + d[i[0]]):
				return True
		if f[i[0]] != oo:
			if b[i[2]] == a[i[2]] * f[i[0]] + d[i[1]]:
				return True
		if a[i[0]] - a[i[1]] != 0 and (b[i[0]] - b[i[1]]) % (a[i[0]] - a[i[1]]) == 0:
			p = (b[i[0]] - b[i[1]]) / (a[i[0]] - a[i[1]])
			q = b[i[0]] - a[i[0]] * p
			if a[i[2]] * p + q == b[i[2]]:
				return True
		if f[i[2]] != oo:
			if a[i[0]] * f[i[2]] - b[i[0]] == a[i[1]] * f[i[2]] - b[i[1]]:
				return True
		if a[i[0]] + d[i[2]] != 0 and a[i[1]] + d[i[2]] != 0:
			if b[i[0]] % (a[i[0]] + d[i[2]]) == 0 and b[i[1]] % (a[i[1]] + d[i[2]]) == 0:
				if b[i[0]] / (a[i[0]] + d[i[2]]) == b[i[1]] / (a[i[1]] + d[i[2]]):
					return True
		if f[i[2]] != oo and f[i[2]] != 0:
			if b[i[1]] % f[i[2]] == 0 and b[i[0]] % f[i[2]] == 0:
				if b[i[1]] / f[i[2]] - a[i[1]] == b[i[0]] / f[i[2]] - a[i[0]]:
					return True
		if a[i[1]] != 0 and a[i[0]] != 0:
			if (b[i[1]] - d[i[2]]) % a[i[1]] == 0 and (b[i[0]] - d[i[2]]) % a[i[0]] == 0:
				if (b[i[1]] - d[i[2]]) / a[i[1]] == (b[i[0]] - d[i[2]]) / a[i[0]]:
					return True
for _ in range(t):
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	c = 0
	d = []
	f = []
	for i in range(3):
		if a[i] == b[i]:
			c += 1
		else:
			d.append(b[i] - a[i])
			if a[i] == 0 or b[i] % a[i] != 0:
				f.append(oo)
			else:
				f.append(b[i] / a[i])
	if c == 0:
		if check1(d) == True or check1(f) == True:
			print(1)
		elif check2(d) == True or check2(f) == True or check2_2(d, f, a, b) == True:
			print(2)
		else:
			print(3)
	elif c == 1:
		if check1(d) == True or check1(f) == True:
			print(1)
		else:
			print(2)
	else:
		print(3 - c)


cases = int(input())

def integer(po):
	if po[0] != 3000000000.0 and po[1] != 3000000000.0:
		return True
	else:
		return False

def lies(point, index, current, target):
	if point[1] + current[index] * point[0] == target[index] or (current[index] + point[1]) * point[0] == target[index] or current[index] * point[0] == target[index] or (current[index] + point[1] == target[index]):
		return True
	else:
		return False

def intercept_case_check(intercepts, p, current, target):
	for i in range(3):
		a = [0, 1, 2]
		a.remove(i)
		point0 = [intercepts[a[0]][0], intercepts[a[1]][1]]
		point6 = [intercepts[a[1]][0], intercepts[a[0]][1]]
		if integer(point0):
			if lies(point0, i, current, target):
				return True
		if integer(point6):
			if lies(point6, i, current, target):
				return True
	return False

def cepts(a, p):
	if a != 0 and p % a == 0:
		x = p // a
	else:
		x = 3000000000.0
	y = p - a
	t = [x, y]
	return t

def solve(a1, p1, a2, p2):
	point = []
	if a1 == a2:
		point.append(3000000000.0)
		point.append(3000000000.0)
		return point
	if (p2 - p1) % (a2 - a1) == 0:
		point.append((p2 - p1) // (a2 - a1))
	else:
		point.append(3000000000.0)
	if (a2 * p1 - a1 * p2) % (a2 - a1) == 0:
		point.append((a2 * p1 - a1 * p2) // (a2 - a1))
	else:
		point.append(3000000000.0)
	return point
for case_parser in range(cases):
	current = list(map(int, input().split()))
	target = list(map(int, input().split()))
	intercepts = [[] for j in range(3)]
	rem = 3
	flagged = []
	p = [[] for j in range(3)]
	p[0] = solve(current[1], target[1], current[2], target[2])
	p[1] = solve(current[2], target[2], current[0], target[0])
	p[2] = solve(current[0], target[0], current[1], target[1])
	for i in range(3):
		intercepts[i] = cepts(current[i], target[i])
	for i in range(3):
		if current[i] == target[i]:
			flagged.append(i)
			rem -= 1
	if rem == 0 or rem == 1:
		print(rem)
		continue
	if rem == 2:
		i = flagged[0]
		dev = [0, 1, 2]
		dev.remove(i)
		if integer(p[i]):
			if p[i][0] == 1 or p[i][1] == 0:
				print(1)
				continue
			else:
				print(2)
				continue
		elif current[dev[0]] == current[dev[1]] and target[dev[0]] == target[dev[1]]:
			print(1)
			continue
		else:
			print(2)
			continue
	parallel = []
	coincident = []
	if current[0] == current[1]:
		if target[0] == target[1]:
			coincident.append(0)
			coincident.append(1)
		else:
			parallel.append(0)
			parallel.append(1)
	if current[1] == current[2]:
		if target[1] == target[2]:
			if 1 not in coincident:
				coincident.append(1)
			if 2 not in coincident:
				coincident.append(2)
		else:
			if 1 not in parallel:
				parallel.append(1)
			if 2 not in parallel:
				parallel.append(2)
	if current[0] == current[2]:
		if target[0] == target[2]:
			if 0 not in coincident:
				coincident.append(0)
			if 2 not in coincident:
				coincident.append(2)
		else:
			if 0 not in parallel:
				parallel.append(0)
			if 2 not in parallel:
				parallel.append(2)
	parallel.sort()
	coincident.sort()
	points = [intercepts[0][1], intercepts[1][1], intercepts[2][1]]
	poins = [intercepts[0][0], intercepts[1][0], intercepts[2][0]]
	for i in range(3):
		if i in coincident and i in parallel:
			parallel.remove(i)
	flag = 0
	if len(parallel) == 3:
		if rem == 3:
			for i in range(3):
				if flag == 1:
					continue
				remain = [0, 1, 2]
				remain.remove(i)
				if points[i] == points[remain[0]] + points[remain[1]]:
					print(2)
					flag = 1
					continue
			if flag == 1:
				continue
			for i in range(3):
				if flag == 1:
					continue
				remain = [0, 1, 2]
				remain.remove(i)
				if poins[i] == poins[remain[0]] * poins[remain[1]]:
					print(2)
					flag = 1
					continue
			if intercept_case_check(intercepts, p, current, target):
				print(2)
				continue
		if flag == 1:
			continue
		if intercept_case_check(intercepts, p, current, target):
			print(2)
			continue
		print(rem)
		continue
	if len(coincident) == 3:
		print(1)
		continue
	df = [0, 1, 2]
	if len(coincident) == 2:
		if len(parallel) == 1:
			if rem == 3:
				print(2)
				continue
		else:
			for i in range(3):
				if i in coincident:
					df.remove(i)
			point = []
			if df[0] == 0:
				point = p[1].copy()
			elif df[0] == 1:
				point = p[0].copy()
			else:
				point = p[0].copy()
			if integer(point):
				if point[0] == 1 or point[1] == 0:
					print(1)
					continue
				else:
					print(2)
					continue
			else:
				print(2)
				continue
	de = [0, 1, 2]
	de1 = [0, 1, 2]
	if len(parallel) == 2:
		point1 = p[parallel[0]].copy()
		point2 = p[parallel[1]].copy()
		if rem == 3:
			if integer(point1):
				q = point1.copy()
				if intercepts[parallel[0]][0] == point1[0] or intercepts[parallel[0]][1] == point1[1]:
					print(2)
					continue
				if point1[0] != 0 and point1[1] % point1[0] == 0:
					q[1] = point1[1] // point1[0]
					if intercepts[parallel[0]][0] == q[0] or intercepts[parallel[0]][1] == q[1]:
						print(2)
						continue
			if integer(point2):
				q = point2.copy()
				if intercepts[parallel[1]][0] == point2[0] or intercepts[parallel[1]][1] == point2[1]:
					print(2)
					continue
				if point2[0] != 0 and point2[1] % point2[0] == 0:
					q[1] = point2[1] // point2[0]
					if intercepts[parallel[1]][0] == q[0] or intercepts[parallel[1]][1] == q[1]:
						print(2)
						continue
			if integer(point1) and point1[0] == 1:
				print(2)
				continue
			if integer(point2) and point2[0] == 1:
				print(2)
				continue
			else:
				if 3000000000.0 not in points:
					for i in range(3):
						if flag == 1:
							continue
						remain = [0, 1, 2]
						remain.remove(i)
						if points[i] == points[remain[0]] + points[remain[1]]:
							print(2)
							flag = 1
							continue
				if flag == 1:
					continue
				if 3000000000.0 not in poins:
					for i in range(3):
						if flag == 1:
							continue
						remain = [0, 1, 2]
						remain.remove(i)
						if poins[i] == poins[remain[0]] * poins[remain[1]]:
							print(2)
							flag = 1
							continue
				if flag == 1:
					continue
		if intercept_case_check(intercepts, p, current, target):
			print(2)
			continue
		print(rem)
		continue
	if len(parallel) == 0 and len(coincident) == 0:
		flag = 0
		if p[0] == p[1] and p[1] == p[2]:
			if integer(p[0]):
				if p[0][0] == 1 or p[0][1] == 0:
					print(1)
					continue
				else:
					print(2)
					continue
		q = p.copy()
		least_count = rem
		for i in range(3):
			if integer(p[i]):
				if p[i][0] != 1 and p[i][1] != 0:
					if intercepts[i][0] == p[i][0] or intercepts[i][1] == p[i][1]:
						least_count = 2
					elif p[i][0] != 0 and p[i][1] % p[i][0] == 0:
						q[i][1] = p[i][1] // p[i][0]
						if intercepts[i][0] == q[i][0] or intercepts[i][1] == q[i][1]:
							least_count = 2
				elif p[i][0] == 1 or p[i][1] == 0:
					least_count = 2
		if least_count == 3:
			for i in range(3):
				if flag == 1:
					continue
				remain = [0, 1, 2]
				remain.remove(i)
				if points[i] == points[remain[0]] + points[remain[1]]:
					print(2)
					flag = 1
					continue
			if flag == 1:
				continue
			for i in range(3):
				if flag == 1:
					continue
				remain = [0, 1, 2]
				remain.remove(i)
				if poins[i] == poins[remain[0]] * poins[remain[1]]:
					print(2)
					flag = 1
					continue
		if flag == 1:
			continue
		if intercept_case_check(intercepts, p, current, target):
			print(2)
			continue
		else:
			print(least_count)
			continue
	else:
		print(rem)
		continue


t = int(input())
for _ in range(t):
	src = list(map(int, input().strip().split()))
	dest = list(map(int, input().strip().split()))
	nsrc = []
	ndest = []
	for i in range(3):
		if not src[i] == dest[i]:
			nsrc.append(src[i])
			ndest.append(dest[i])
	if len(nsrc) == 0:
		print(0)
	elif len(nsrc) == 1:
		print(1)
	elif len(nsrc) == 2:
		(x1, x2) = (nsrc[0], nsrc[1])
		(y1, y2) = (ndest[0], ndest[1])
		if x1 != 0 and x2 != 0 and (y1 % x1 == 0) and (y2 % x2 == 0) and (y1 // x1 == y2 // x2) or y2 - x2 == y1 - x1:
			print(1)
		else:
			print(2)
	else:
		(x1, x2, x3) = (nsrc[0], nsrc[1], nsrc[2])
		(y1, y2, y3) = (ndest[0], ndest[1], ndest[2])
		if x1 != 0 and x2 != 0 and (x3 != 0) and (y1 % x1 == 0) and (y2 % x2 == 0) and (y3 % x3 == 0) and (y1 // x1 == y2 // x2) and (y2 // x2 == y3 // x3) or (y3 - x3 == y2 - x2 and y2 - x2 == y1 - x1):
			print(1)
			continue
		elif y1 == y2 and y2 == y3:
			print(2)
			continue
		else:
			if x1 != 0 and y1 % x1 == 0:
				r1 = y1 // x1
				if y2 - x2 * r1 == y3 - x3 * r1:
					print(2)
					continue
				if y2 == x2 * r1 or y3 == x3 * r1:
					print(2)
					continue
				if y2 - x2 * r1 == y3 - x3 or y3 - x3 * r1 == y2 - x2:
					print(2)
					continue
				if r1 != 0 and x2 != 0 and (x3 != 0) and (y2 % (x2 * r1) == 0) and (y3 % x3 == 0) and (y3 // x3 == y2 // (x2 * r1)):
					print(2)
					continue
				if r1 != 0 and x2 != 0 and (x3 != 0) and (y3 % (x3 * r1) == 0) and (y2 % x2 == 0) and (y2 // x2 == y3 // (x3 * r1)):
					print(2)
					continue
			d1 = y1 - x1
			if y2 == x2 + d1 or y3 == x3 + d1:
				print(2)
				continue
			if x2 + d1 != 0 and x3 != 0 and (y2 % (x2 + d1) == 0) and (y3 % x3 == 0) and (y2 // (x2 + d1) == y3 // x3):
				print(2)
				continue
			if x3 + d1 != 0 and x2 != 0 and (y2 % x2 == 0) and (y3 % (x3 + d1) == 0) and (y2 // x2 == y3 // (x3 + d1)):
				print(2)
				continue
			if x3 != 0 and x2 != 0 and ((y2 - d1) % x2 == 0) and ((y3 - d1) % x3 == 0) and ((y2 - d1) // x2 == (y3 - d1) // x3):
				print(2)
				continue
			if x3 + d1 != 0 and x2 + d1 != 0 and (y2 % (x2 + d1) == 0) and (y3 % (x3 + d1) == 0) and (y2 // (x2 + d1) == y3 // (x3 + d1)):
				print(2)
				continue
			if y2 - (x2 + d1) == y3 - x3 or y2 - x2 == y3 - (x3 + d1):
				print(2)
				continue
			(x1, x2, x3) = (x2, x1, x3)
			(y1, y2, y3) = (y2, y1, y3)
			if x1 != 0 and y1 % x1 == 0:
				r1 = y1 // x1
				if y2 - x2 * r1 == y3 - x3 * r1:
					print(2)
					continue
				if y2 == x2 * r1 or y3 == x3 * r1:
					print(2)
					continue
				if y2 - x2 * r1 == y3 - x3 or y3 - x3 * r1 == y2 - x2:
					print(2)
					continue
				if r1 != 0 and x2 != 0 and (x3 != 0) and (y2 % (x2 * r1) == 0) and (y3 % x3 == 0) and (y3 // x3 == y2 // (x2 * r1)):
					print(2)
					continue
				if r1 != 0 and x2 != 0 and (x3 != 0) and (y3 % (x3 * r1) == 0) and (y2 % x2 == 0) and (y2 // x2 == y3 // (x3 * r1)):
					print(2)
					continue
			d1 = y1 - x1
			if y2 == x2 + d1 or y3 == x3 + d1:
				print(2)
				continue
			if x2 + d1 != 0 and x3 != 0 and (y2 % (x2 + d1) == 0) and (y3 % x3 == 0) and (y2 // (x2 + d1) == y3 // x3):
				print(2)
				continue
			if x3 + d1 != 0 and x2 != 0 and (y2 % x2 == 0) and (y3 % (x3 + d1) == 0) and (y2 // x2 == y3 // (x3 + d1)):
				print(2)
				continue
			if x3 != 0 and x2 != 0 and ((y2 - d1) % x2 == 0) and ((y3 - d1) % x3 == 0) and ((y2 - d1) // x2 == (y3 - d1) // x3):
				print(2)
				continue
			if x3 + d1 != 0 and x2 + d1 != 0 and (y2 % (x2 + d1) == 0) and (y3 % (x3 + d1) == 0) and (y2 // (x2 + d1) == y3 // (x3 + d1)):
				print(2)
				continue
			if y2 - (x2 + d1) == y3 - x3 or y2 - x2 == y3 - (x3 + d1):
				print(2)
				continue
			(x1, x2, x3) = (x3, x2, x1)
			(y1, y2, y3) = (y3, y2, y1)
			if x1 != 0 and y1 % x1 == 0:
				r1 = y1 // x1
				if y2 - x2 * r1 == y3 - x3 * r1:
					print(2)
					continue
				if y2 == x2 * r1 or y3 == x3 * r1:
					print(2)
					continue
				if y2 - x2 * r1 == y3 - x3 or y3 - x3 * r1 == y2 - x2:
					print(2)
					continue
				if r1 != 0 and x2 != 0 and (x3 != 0) and (y2 % (x2 * r1) == 0) and (y3 % x3 == 0) and (y3 // x3 == y2 // (x2 * r1)):
					print(2)
					continue
				if r1 != 0 and x2 != 0 and (x3 != 0) and (y3 % (x3 * r1) == 0) and (y2 % x2 == 0) and (y2 // x2 == y3 // (x3 * r1)):
					print(2)
					continue
			d1 = y1 - x1
			if y2 == x2 + d1 or y3 == x3 + d1:
				print(2)
				continue
			if x2 + d1 != 0 and x3 != 0 and (y2 % (x2 + d1) == 0) and (y3 % x3 == 0) and (y2 // (x2 + d1) == y3 // x3):
				print(2)
				continue
			if x3 + d1 != 0 and x2 != 0 and (y2 % x2 == 0) and (y3 % (x3 + d1) == 0) and (y2 // x2 == y3 // (x3 + d1)):
				print(2)
				continue
			if x3 != 0 and x2 != 0 and ((y2 - d1) % x2 == 0) and ((y3 - d1) % x3 == 0) and ((y2 - d1) // x2 == (y3 - d1) // x3):
				print(2)
				continue
			if x3 + d1 != 0 and x2 + d1 != 0 and (y2 % (x2 + d1) == 0) and (y3 % (x3 + d1) == 0) and (y2 // (x2 + d1) == y3 // (x3 + d1)):
				print(2)
				continue
			if y2 - (x2 + d1) == y3 - x3 or y2 - x2 == y3 - (x3 + d1):
				print(2)
				continue
			if x1 != x2 and x2 != x3 and (x3 != x1):
				if (y2 - y1) * (x3 - x1) == (x2 - x1) * (y3 - y1) and (y2 - y1) % (x2 - x1) == 0:
					print(2)
					continue
			print(3)


def try1(v1, v2, v3, v4):
	if v3 - v1 == v4 - v2:
		return 1
	if v1 == 0 or v2 == 0:
		return 0
	if v3 % v1 == 0 and v4 % v2 == 0 and (v3 // v1 == v4 // v2):
		return 1
	return 0

def try2(v1, v2, v3, v4, v5, v6):
	if v4 - v1 == v5 - v2 and v5 - v2 == v6 - v3:
		return 1
	if v1 == 0 or v2 == 0 or v3 == 0:
		return 0
	if v4 % v1 == 0 and v5 % v2 == 0 and (v6 % v3 == 0) and (v4 // v1 == v5 // v2) and (v5 // v2 == v6 // v3):
		return 1
	return 0
T = int(input())
for t in range(T):
	(a, b, c) = map(int, input().split(' '))
	(p, q, r) = map(int, input().split(' '))
	if a == p and b == q and (c == r):
		print('0')
		continue
	if a == p and b == q or (a == p and c == r) or (b == q and c == r):
		print(1)
		continue
	if a == p and try1(b, c, q, r) or (b == q and try1(a, c, p, r)) or (c == r and try1(a, b, p, q)) or try2(a, b, c, p, q, r):
		print(1)
		continue
	if a == p or b == q or c == r:
		print(2)
		continue
	if try1(a, b, p, q) or try1(a, c, p, r) or try1(b, c, q, r):
		print(2)
		continue
	diff1 = p - a
	diff2 = q - b
	diff3 = r - c
	if diff1 + diff2 == diff3 or diff2 + diff3 == diff1 or diff1 + diff3 == diff2:
		print(2)
		continue
	flag = 1
	if a == 0 or b == 0 or c == 0:
		flag = 0
	if flag == 1:
		qnt1 = p // a
		qnt2 = q // b
		qnt3 = r // c
		rem1 = p % a
		rem2 = q % b
		rem3 = r % c
		if rem1 == 0 and rem2 == 0 and (rem3 == 0) and (qnt1 * qnt2 == qnt3 or qnt1 * qnt3 == qnt2 or qnt2 * qnt3 == qnt1):
			print(2)
			continue
	if a != 0 and p % a == 0:
		qnt1 = p // a
		if qnt1 != 0 and r % qnt1 == 0:
			if q - b == r // qnt1 - c:
				print(2)
				continue
		if qnt1 != 0 and q % qnt1 == 0:
			if r - c == q // qnt1 - b:
				print(2)
				continue
	if b != 0 and q % b == 0:
		qnt1 = q // b
		if qnt1 != 0 and r % qnt1 == 0:
			if p - a == r // qnt1 - c:
				print(2)
				continue
		if qnt1 != 0 and p % qnt1 == 0:
			if r - c == p // qnt1 - a:
				print(2)
				continue
	if c != 0 and r % c == 0:
		qnt1 = r // c
		if qnt1 != 0 and p % qnt1 == 0:
			if q - b == p // qnt1 - a:
				print(2)
				continue
		if qnt1 != 0 and q % qnt1 == 0:
			if p - a == q // qnt1 - b:
				print(2)
				continue
	if a != 0 and (p - diff2) % a == 0:
		if c != 0 and r % c == 0 and ((p - diff2) // a == r // c):
			print(2)
			continue
	if a != 0 and (p - diff3) % a == 0:
		if b != 0 and q % b == 0 and ((p - diff3) // a == q // b):
			print(2)
			continue
	if b != 0 and (q - diff1) % b == 0:
		if c != 0 and r % c == 0 and ((q - diff1) // b == r // c):
			print(2)
			continue
	if b != 0 and (q - diff3) % b == 0:
		if a != 0 and p % a == 0 and ((q - diff3) // b == p // a):
			print(2)
			continue
	if c != 0 and (r - diff1) % c == 0:
		if b != 0 and q % b == 0 and ((r - diff1) // c == q // b):
			print(2)
			continue
	if c != 0 and (r - diff2) % c == 0:
		if a != 0 and p % a == 0 and ((r - diff2) // c == p // a):
			print(2)
			continue
	if a != 0 and p % a == 0:
		qnt1 = p // a
		if qnt1 != 0 and q % qnt1 == 0 and (r % qnt1 == 0):
			qnt2 = q // qnt1
			qnt3 = r // qnt1
			if qnt2 - b == qnt3 - c:
				print(2)
				continue
	if b != 0 and q % b == 0:
		qnt1 = q // b
		if qnt1 != 0 and p % qnt1 == 0 and (r % qnt1 == 0):
			qnt2 = p // qnt1
			qnt3 = r // qnt1
			if qnt2 - a == qnt3 - c:
				print(2)
				continue
	if c != 0 and r % c == 0:
		qnt1 = r // c
		if qnt1 != 0 and p % qnt1 == 0 and (q % qnt1 == 0):
			qnt2 = p // qnt1
			qnt3 = q // qnt1
			if qnt2 - a == qnt3 - b:
				print(2)
				continue
	if b != 0 and c != 0 and ((q - diff1) % b == 0) and ((r - diff1) % c == 0) and ((q - diff1) // b == (r - diff1) // c):
		print(2)
		continue
	if a != 0 and b != 0 and ((q - diff3) % b == 0) and ((p - diff3) % a == 0) and ((q - diff3) // b == (p - diff3) // a):
		print(2)
		continue
	if a != 0 and c != 0 and ((p - diff2) % a == 0) and ((r - diff2) % c == 0) and ((p - diff2) // a == (r - diff2) // c):
		print(2)
		continue
	if b + diff1 != 0 and c + diff1 != 0 and (q % (b + diff1) == 0) and (r % (c + diff1) == 0) and (q // (b + diff1) == r // (c + diff1)):
		print(2)
		continue
	if a + diff2 != 0 and c + diff2 != 0 and (p % (a + diff2) == 0) and (r % (c + diff2) == 0) and (p // (a + diff2) == r // (c + diff2)):
		print(2)
		continue
	if b + diff3 != 0 and a + diff3 != 0 and (q % (b + diff3) == 0) and (p % (a + diff3) == 0) and (q // (b + diff3) == p // (a + diff3)):
		print(2)
		continue
	if a != 0 and p % a == 0:
		qnt1 = p // a
		if q - b * qnt1 == r - c * qnt1:
			print(2)
			continue
	if b != 0 and q % b == 0:
		qnt1 = q // b
		if p - a * qnt1 == r - c * qnt1:
			print(2)
			continue
	if c != 0 and r % c == 0:
		qnt1 = r // c
		if q - b * qnt1 == p - a * qnt1:
			print(2)
			continue
	if a - b != 0 and (p - q) % (a - b) == 0:
		y1 = (p - q) // (a - b)
		if y1 != 0 and p % y1 == 0:
			x1 = p // y1 - a
			if (c + x1) * y1 == r:
				print(2)
				continue
	if a - c != 0 and (p - r) % (a - c) == 0:
		y1 = (p - r) // (a - c)
		if y1 != 0 and p % y1 == 0:
			x1 = p // y1 - a
			if (b + x1) * y1 == q:
				print(2)
				continue
	if b - c != 0 and (q - r) % (b - c) == 0:
		y1 = (q - r) // (b - c)
		if y1 != 0 and q % y1 == 0:
			x1 = q // y1 - b
			if (a + x1) * y1 == p:
				print(2)
				continue
	if a - b != 0 and (p - q) % (a - b) == 0:
		x1 = (p - q) // (a - b)
		y1 = p - a * x1
		if c * x1 + y1 == r:
			print(2)
			continue
	if a - c != 0 and (p - r) % (a - c) == 0:
		x1 = (p - r) // (a - c)
		y1 = p - a * x1
		if b * x1 + y1 == q:
			print(2)
			continue
	if c - b != 0 and (r - q) % (c - b) == 0:
		x1 = (r - q) // (c - b)
		y1 = r - c * x1
		if a * x1 + y1 == p:
			print(2)
			continue
	print(3)
	continue


import math
t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	(d, e, f) = map(int, input().split())
	ans = 3
	s1 = d - a
	s2 = e - b
	s3 = f - c
	if a == 0:
		r1 = 1
		q1 = 0
	else:
		if d % a == 0:
			r1 = 0
		else:
			r1 = 1
		q1 = d // a
	if b == 0:
		r2 = 1
		q2 = 0
	else:
		if e % b == 0:
			r2 = 0
		else:
			r2 = 1
		q2 = e // b
	if c == 0:
		r3 = 1
		q3 = 0
	else:
		if f % c == 0:
			r3 = 0
		else:
			r3 = 1
		q3 = f // c
	if s1 == 0 and s2 == 0 and (s3 == 0):
		ans = min(ans, 0)
	if s1 == 0 and s2 == 0:
		ans = min(ans, 1)
	if s2 == 0 and s3 == 0:
		ans = min(ans, 1)
	if s1 == 0 and s3 == 0:
		ans = min(ans, 1)
	if s1 == 0:
		if s2 == s3 or (r2 == 0 and r3 == 0 and (q2 == q3)):
			ans = min(ans, 1)
		else:
			ans = min(ans, 2)
	if s2 == 0:
		if s1 == s3 or (r1 == 0 and r3 == 0 and (q1 == q3)):
			ans = min(ans, 1)
		else:
			ans = min(ans, 2)
	if s3 == 0:
		if s1 == s2 or (r1 == 0 and r2 == 0 and (q1 == q2)):
			ans = min(ans, 1)
		else:
			ans = min(ans, 2)
	if s1 == s2 and s1 == s3:
		ans = min(ans, 1)
	if s1 == s2 or s1 == s3 or s2 == s3:
		ans = min(ans, 2)
	if s1 + s2 == s3 or s1 + s3 == s2 or s2 + s3 == s1:
		ans = min(ans, 2)
	if r1 == 0 and r2 == 0 and (r3 == 0):
		if q1 == q2 and q1 == q3:
			ans = min(ans, 1)
		if q1 * q2 == q3 or q1 * q3 == q2 or q2 * q3 == q1:
			ans = min(ans, 2)
	if r1 == 0 and r2 == 0 and (q1 == q2):
		ans = min(ans, 2)
	if r2 == 0 and r3 == 0 and (q2 == q3):
		ans = min(ans, 2)
	if r1 == 0 and r3 == 0 and (q1 == q3):
		ans = min(ans, 2)
	if r2 == 0 and c * q2 + s1 == f:
		ans = min(ans, 2)
	if r3 == 0 and b * q3 + s1 == e:
		ans = min(ans, 2)
	if c != 0 and b != 0 and ((f - s1) % c == 0) and ((e - s1) % b == 0):
		if (f - s1) // c == (e - s1) // b:
			ans = min(ans, 2)
	if r1 == 0 and c * q1 + s2 == f:
		ans = min(ans, 2)
	if r3 == 0 and a * q3 + s2 == d:
		ans = min(ans, 2)
	if a != 0 and c != 0 and ((d - s2) % a == 0) and ((f - s2) % c == 0):
		if (d - s2) // a == (f - s2) // c:
			ans = min(ans, 2)
	if r2 == 0 and a * q2 + s3 == d:
		ans = min(ans, 2)
	if r1 == 0 and b * q1 + s3 == e:
		ans = min(ans, 2)
	if a != 0 and b != 0 and ((d - s3) % a == 0) and ((e - s3) % b == 0):
		if (d - s3) // a == (e - s3) // b:
			ans = min(ans, 2)
	if r1 == 0 and e - b * q1 == f - c * q1 or (r2 == 0 and d - a * q2 == f - c * q2) or (r3 == 0 and d - a * q3 == e - b * q3):
		ans = min(ans, 2)
	p = a - b
	q = d - e
	r = b - c
	s = e - f
	t1 = math.gcd(abs(p), abs(q))
	t2 = math.gcd(abs(r), abs(s))
	if t1 != 0:
		p //= t1
		q //= t1
	if t2 != 0:
		r //= t2
		s //= t2
	if (p == r and q == s or (p == -r and q == -s)) and abs(p) == 1:
		ans = min(ans, 2)
	if r1 == 0:
		x = q1
		if (c + s2) * x == f or (b + s3) * x == e:
			ans = min(ans, 2)
		if x != 0 and e % x == 0 and (f % x == 0) and (f // x - c == e // x - b):
			ans = min(ans, 2)
	if r2 == 0:
		x = q2
		if (c + s1) * x == f or (a + s3) * x == d:
			ans = min(ans, 2)
		if x != 0 and d % x == 0 and (f % x == 0) and (d // x - a == f // x - c):
			ans = min(ans, 2)
	if r3 == 0:
		x = q3
		if (a + s2) * x == d or (b + s1) * x == e:
			ans = min(ans, 2)
		if x != 0 and d % x == 0 and (e % x == 0) and (d // x - a == e // x - b):
			ans = min(ans, 2)
	if a + s2 != 0 and c + s2 != 0 and (d % (a + s2) == 0) and (f % (c + s2) == 0) and (d // (a + s2) == f // (c + s2)):
		ans = min(ans, 2)
	if a + s3 != 0 and b + s3 != 0 and (d % (a + s3) == 0) and (e % (b + s3) == 0) and (d // (a + s3) == e // (b + s3)):
		ans = min(ans, 2)
	if b + s1 != 0 and c + s1 != 0 and (e % (b + s1) == 0) and (f % (c + s1) == 0) and (e // (b + s1) == f // (c + s1)):
		ans = min(ans, 2)
	print(ans)


def d1d2(p, q, r, a, b, c):
	if p == 0 or q == 0 or r == 0:
		return False
	if a % p == 0 and b % q == 0:
		d1 = a // p
		d2 = b // q
		if c == r * d1 * d2:
			return True
		return False
	return False

def e1e2(p, q, r, a, b, c):
	e1 = a - p
	e2 = b - q
	return c == r + e1 + e2

def d3e3(p, q, r, a, b, c):
	delta = [0, 0, 0]
	delta[0] = p - q
	if delta[0] == 0:
		return False
	delta[1] = a - b
	delta[2] = p * b - q * a
	if delta[1] % delta[0] == 0 and delta[2] % delta[0] == 0:
		val_d = delta[1] // delta[0]
		val_e = delta[2] // delta[0]
		return c == r * val_d + val_e
	else:
		return False

def d3e2(p, q, r, a, b, c):
	delta = [0, 0, 0]
	delta[0] = p - q
	if delta[0] == 0:
		return False
	delta[1] = a - b
	delta[2] = p * b - q * a
	if delta[1] % delta[0] == 0 and delta[2] % delta[0] == 0:
		val_d = delta[1] // delta[0]
		val_e = delta[2] // delta[0]
		return c == r * val_d
	else:
		return False

def d2e3(p, q, r, a, b, c):
	delta = [0, 0, 0]
	delta[0] = p - q
	if delta[0] == 0:
		return False
	delta[1] = a - b
	delta[2] = p * b - q * a
	if delta[1] % delta[0] == 0 and delta[2] % delta[0] == 0:
		val_d = delta[1] // delta[0]
		val_e = delta[2] // delta[0]
		return c == r + val_e
	else:
		return False

def d2e2(p, q, r, a, b, c):
	if q != 0 and b % q == 0:
		d = b // q
		e = c - r
		assert e != 0, 'already checked, one same'
		return a == p * d + e
	return False

def e3d2(p, q, r, a, b, c):
	assert c != r, '1 same'
	e = c - r
	if p != -e and q != -e and (a % (p + e) == 0) and (b % (q + e) == 0):
		d1 = a // (p + e)
		d2 = b // (q + e)
		return d1 != 1 and d1 == d2
	return False

def e2d2(p, q, r, a, b, c):
	if r != 0 and c % r == 0:
		d = c // r
		e = b - q
		assert d != 1 and e != 0, '1 or 2 same'
		return a == (p + e) * d
	return False

def modified(src, dst):
	(p, q, r) = src
	(a, b, c) = dst
	if p == a and q == b and (r == c):
		print(0)
		return
	if p == a and q == b:
		if r != c:
			print(1)
			return
		assert True, 'Should not have come here1'
	if q == b and r == c:
		if p != a:
			print(1)
			return
		assert True, 'Should not have come here2'
	if r == c and p == a:
		if q != b:
			print(1)
			return
		assert True, 'Should not have come here3'
	if p == a:
		if b - q == c - r:
			print(1)
			return
		if q != 0 and r != 0 and (b % q == 0) and (b % q == c % r) and (b // q == c // r):
			print(1)
			return
		print(2)
		return
	if q == b:
		if c - r == a - p:
			print(1)
			return
		if p != 0 and r != 0 and (a % p == 0) and (a % p == c % r) and (a // p == c // r):
			print(1)
			return
		print(2)
		return
	if r == c:
		if b - q == a - p:
			print(1)
			return
		if p != 0 and q != 0 and (a % p == 0) and (a % p == b % q) and (a // p == b // q):
			print(1)
			return
		print(2)
		return
	if p - a == q - b and q - b == r - c:
		print(1)
		return
	if p != 0 and q != 0 and (r != 0):
		if a % p == 0 and a % p == b % q and (b % q == c % r):
			if a // p == b // q and b // q == c // r:
				print(1)
				return
	if p - a == q - b:
		print(2)
		return
	if p != 0 and q != 0 and (a % p == 0) and (a % p == b % q) and (a // p == b // q):
		print(2)
		return
	if r - c == q - b:
		print(2)
		return
	if r != 0 and q != 0 and (c % r == 0) and (c % r == b % q) and (c // r == b // q):
		print(2)
		return
	if p - a == r - c:
		print(2)
		return
	if p != 0 and r != 0 and (a % p == 0) and (a % p == c % r) and (a // p == c // r):
		print(2)
		return
	if d1d2(p, q, r, a, b, c) or d1d2(q, r, p, b, c, a) or d1d2(r, p, q, c, a, b):
		print(2)
		return
	if e1e2(p, q, r, a, b, c) or e1e2(q, r, p, b, c, a) or e1e2(r, p, q, c, a, b):
		print(2)
		return
	if d3e3(p, q, r, a, b, c):
		print(2)
		return
	if d3e2(p, q, r, a, b, c) or d3e2(q, r, p, b, c, a) or d3e2(r, p, q, c, a, b):
		print(2)
		return
	if d2e3(p, q, r, a, b, c) or d2e3(q, r, p, b, c, a) or d2e3(r, p, q, c, a, b):
		print(2)
		return
	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):
		print(2)
		return
	if e3d2(p, q, r, a, b, c) or e3d2(q, r, p, b, c, a) or e3d2(r, p, q, c, a, b):
		print(2)
		return
	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):
		print(2)
		return
	print(3)
for _ in range(int(input())):
	src = tuple(map(int, input().split()))
	dst = tuple(map(int, input().split()))
	modified(src, dst)


import math

def ifDeno(a1, b1, c1, a2, b2, c2):
	if a2 == b2 == c2 != 0:
		return True
	if a2 == b2:
		if c1 == c2:
			return True
		if c2 == 0:
			return True
		if c1 + a2 == c2:
			return True
	if b2 == c2:
		if a1 == a2:
			return True
		if a2 == 0:
			return True
		if a1 + b2 == a2:
			return True
	if c2 == a2:
		if b1 == b2:
			return True
		if b2 == 0:
			return True
		if b1 + a2 == b2:
			return True
	return False

def ifCombo(x, y, z, x2, y2, z2):
	if x + y == z or y + z == x or z + x == y:
		return True
	if x2 == math.ceil(x2) and y2 == math.ceil(y2) and (z2 == math.ceil(z2)):
		if x2 * y2 == z2 or y2 * z2 == x2 or z2 * x2 == y2:
			return True
	return False

def ifTwoBrute2(a1, b1, c1, a2, b2, c2):
	up1 = a2 - a1
	up2 = b2 - b1
	up3 = c2 - c1
	down1 = -a2 - a1
	down2 = -b2 - b1
	down3 = -c2 - c1
	for i in range(min(up1, down1), max(up1, down1) + 1):
		try:
			if a2 % (a1 + i) == 0 and b2 % (b1 + i) == 0 and (c2 % (c1 + i) == 0) and (a2 // (a1 + i) == b2 // (b1 + i) == c2 // (c1 + i)):
				return True
		except:
			n = 0
		try:
			if a2 % (a1 + i) == 0 and b2 % (b1 + i) == 0 and (a2 // (a1 + i) == b2 // (b1 + i)):
				if c1 == c2 or c1 + i == c2 or c1 * (a2 // (a1 + i)) == c2:
					return True
		except:
			n = 0
		try:
			if b2 % (b1 + i) == 0 and c2 % (c1 + i) == 0 and (b2 // (b1 + i) == c2 // (c1 + i)):
				if a1 == a2 or a1 + i == a2 or a1 * (b2 // (b1 + i)) == a2:
					return True
		except:
			n = 0
		try:
			if c2 % (c1 + i) == 0 and a2 % (a1 + i) == 0 and (c2 // (c1 + i) == a2 // (a1 + i)):
				if b1 == b2 or b1 + i == b2 or b1 * (a2 // (a1 + i)) == b2:
					return True
		except:
			n = 0
	for i in range(min(up2, down2), max(up2, down2) + 1):
		try:
			if a2 % (a1 + i) == 0 and b2 % (b1 + i) == 0 and (c2 % (c1 + i) == 0) and (a2 // (a1 + i) == b2 // (b1 + i) == c2 // (c1 + i)):
				return True
		except:
			n = 0
		try:
			if a2 % (a1 + i) == 0 and b2 % (b1 + i) == 0 and (a2 // (a1 + i) == b2 // (b1 + i)):
				if c1 == c2 or c1 + i == c2 or c1 * (a2 // (a1 + i)) == c2:
					return True
		except:
			n = 0
		try:
			if b2 % (b1 + i) == 0 and c2 % (c1 + i) == 0 and (b2 // (b1 + i) == c2 // (c1 + i)):
				if a1 == a2 or a1 + i == a2 or a1 * (b2 // (b1 + i)) == a2:
					return True
		except:
			n = 0
		try:
			if c2 % (c1 + i) == 0 and a2 % (a1 + i) == 0 and (c2 // (c1 + i) == a2 // (a1 + i)):
				if b1 == b2 or b1 + i == b2 or b1 * (a2 // (a1 + i)) == b2:
					return True
		except:
			n = 0
	for i in range(min(up3, down3), max(up3, down3) + 1):
		try:
			if a2 % (a1 + i) == 0 and b2 % (b1 + i) == 0 and (c2 % (c1 + i) == 0) and (a2 // (a1 + i) == b2 // (b1 + i) == c2 // (c1 + i)):
				return True
		except:
			n = 0
		try:
			if a2 % (a1 + i) == 0 and b2 % (b1 + i) == 0 and (a2 // (a1 + i) == b2 // (b1 + i)):
				if c1 == c2 or c1 + i == c2 or c1 * (a2 // (a1 + i)) == c2:
					return True
		except:
			n = 0
		try:
			if b2 % (b1 + i) == 0 and c2 % (c1 + i) == 0 and (b2 // (b1 + i) == c2 // (c1 + i)):
				if a1 == a2 or a1 + i == a2 or a1 * (b2 // (b1 + i)) == a2:
					return True
		except:
			n = 0
		try:
			if c2 % (c1 + i) == 0 and a2 % (a1 + i) == 0 and (c2 // (c1 + i) == a2 // (a1 + i)):
				if b1 == b2 or b1 + i == b2 or b1 * (a2 // (a1 + i)) == b2:
					return True
		except:
			n = 0
	for i in range(min(up1, down1), max(up1, down1) + 1):
		try:
			if a2 - a1 * i == b2 - b1 * i == c2 - c1 * i:
				return True
		except:
			n = 0
		try:
			if a2 - a1 * i == b2 - b1 * i:
				if c1 == c2 or c1 * i == c2 or c1 + (a2 - a1 * i) == c2:
					return True
		except:
			n = 0
		try:
			if b2 - b1 * i == c2 - c1 * i:
				if a1 == a2 or a1 * i == a2 or a1 + (b2 - b1 * i) == a2:
					return True
		except:
			n = 0
		try:
			if c2 - c1 * i == a2 - a1 * i:
				if b1 == b2 or b1 * i == b2 or b1 + (c2 - c1 * i) == b2:
					return True
		except:
			n = 0
	for i in range(min(up2, down2), max(up2, down2) + 1):
		try:
			if a2 - a1 * i == b2 - b1 * i == c2 - c1 * i:
				return True
		except:
			n = 0
		try:
			if a2 - a1 * i == b2 - b1 * i:
				if c1 == c2 or c1 * i == c2 or c1 + (a2 - a1 * i) == c2:
					return True
		except:
			n = 0
		try:
			if b2 - b1 * i == c2 - c1 * i:
				if a1 == a2 or a1 * i == a2 or a1 + (b2 - b1 * i) == a2:
					return True
		except:
			n = 0
		try:
			if c2 - c1 * i == a2 - a1 * i:
				if b1 == b2 or b1 * i == b2 or b1 + (c2 - c1 * i) == b2:
					return True
		except:
			n = 0
	for i in range(min(up3, down3), max(up3, down3) + 1):
		try:
			if a2 - a1 * i == b2 - b1 * i == c2 - c1 * i:
				return True
		except:
			n = 0
		try:
			if a2 - a1 * i == b2 - b1 * i:
				if c1 == c2 or c1 * i == c2 or c1 + (a2 - a1 * i) == c2:
					return True
		except:
			n = 0
		try:
			if b2 - b1 * i == c2 - c1 * i:
				if a1 == a2 or a1 * i == a2 or a1 + (b2 - b1 * i) == a2:
					return True
		except:
			n = 0
		try:
			if c2 - c1 * i == a2 - a1 * i:
				if b1 == b2 or b1 * i == b2 or b1 + (c2 - c1 * i) == b2:
					return True
		except:
			n = 0
	return False

def ifTwoBrute(a1, b1, c1, a2, b2, c2):
	up1 = a2 - a1
	up2 = b2 - b1
	up3 = c2 - c1
	down1 = -a2 - a1
	down2 = -b2 - b1
	down3 = -c2 - c1
	upCurrent = 0
	downCurrent = 0
	status = [False, False, False]
	status1 = [False, False, False]
	if a1 == a2:
		upCurrent += 1
		downCurrent += 1
		status[0] = True
		status1[0] = True
	if b1 == b2:
		upCurrent += 1
		downCurrent += 1
		status[1] = True
		status1[1] = True
	if c1 == c2:
		upCurrent += 1
		downCurrent += 1
		status[2] = True
		status1[2] = True
	i = 0
	while upCurrent < 2:
		if i > up1 and status[0] == False:
			upCurrent += 1
			status[0] = True
		if i > up2 and status[1] == False:
			upCurrent += 1
			status[1] = True
		if i > up3 and status[2] == False:
			upCurrent += 1
			status[2] = True
		try:
			if a2 % (a1 + i) == 0 and b2 % (b1 + i) == 0 and (c2 % (c1 + i) == 0) and (a2 // (a1 + i) == b2 // (b1 + i) == c2 // (c1 + i)):
				return True
		except:
			n = 0
		try:
			if a2 % (a1 + i) == 0 and b2 % (b1 + i) == 0 and (a2 // (a1 + i) == b2 // (b1 + i)):
				if c1 == c2 or c1 + i == c2 or c1 * (a2 // (a1 + i)) == c2:
					return True
		except:
			n = 0
		try:
			if b2 % (b1 + i) == 0 and c2 % (c1 + i) == 0 and (b2 // (b1 + i) == c2 // (c1 + i)):
				if a1 == a2 or a1 + i == a2 or a1 * (b2 // (b1 + i)) == a2:
					return True
		except:
			n = 0
		try:
			if c2 % (c1 + i) == 0 and a2 % (a1 + i) == 0 and (c2 // (c1 + i) == a2 // (a1 + i)):
				if b1 == b2 or b1 + i == b2 or b1 * (a2 // (a1 + i)) == b2:
					return True
		except:
			n = 0
		i += 1
	i = 0
	while downCurrent < 2:
		if i < down1 and status1[0] == False:
			downCurrent += 1
			status1[0] = True
		if i < down2 and status1[1] == False:
			downCurrent += 1
			status1[1] = True
		if i < down3 and status1[2] == False:
			downCurrent += 1
			status1[2] = True
		try:
			if a2 % (a1 + i) == 0 and b2 % (b1 + i) == 0 and (c2 % (c1 + i) == 0) and (a2 // (a1 + i) == b2 // (b1 + i) == c2 // (c1 + i)):
				return True
		except:
			n = 0
		try:
			if a2 % (a1 + i) == 0 and b2 % (b1 + i) == 0 and (a2 // (a1 + i) == b2 // (b1 + i)):
				if c1 == c2 or c1 + i == c2 or c1 * (a2 // (a1 + i)) == c2:
					return True
		except:
			n = 0
		try:
			if b2 % (b1 + i) == 0 and c2 % (c1 + i) == 0 and (b2 // (b1 + i) == c2 // (c1 + i)):
				if a1 == a2 or a1 + i == a2 or a1 * (b2 // (b1 + i)) == a2:
					return True
		except:
			n = 0
		try:
			if c2 % (c1 + i) == 0 and a2 % (a1 + i) == 0 and (c2 // (c1 + i) == a2 // (a1 + i)):
				if b1 == b2 or b1 + i == b2 or b1 * (a2 // (a1 + i)) == b2:
					return True
		except:
			n = 0
		i -= 1
	up1 = a2 - a1
	up2 = b2 - b1
	up3 = c2 - c1
	down1 = -a2 - a1
	down2 = -b2 - b1
	down3 = -c2 - c1
	upCurrent = 0
	downCurrent = 0
	status = [False, False, False]
	status1 = [False, False, False]
	if a1 == a2:
		upCurrent += 1
		downCurrent += 1
		status[0] = True
		status1[0] = True
	if b1 == b2:
		upCurrent += 1
		downCurrent += 1
		status[1] = True
		status1[1] = True
	if c1 == c2:
		upCurrent += 1
		downCurrent += 1
		status[2] = True
		status1[2] = True
	i = 0
	while upCurrent < 2:
		if i > up1 and status[0] == False:
			upCurrent += 1
			status[0] = True
		if i > up2 and status[1] == False:
			upCurrent += 1
			status[1] = True
		if i > up3 and status[2] == False:
			upCurrent += 1
			status[2] = True
		try:
			if a2 - a1 * i == b2 - b1 * i == c2 - c1 * i:
				return True
		except:
			n = 0
		try:
			if a2 - a1 * i == b2 - b1 * i:
				if c1 == c2 or c1 * i == c2 or c1 + (a2 - a1 * i) == c2:
					return True
		except:
			n = 0
		try:
			if b2 - b1 * i == c2 - c1 * i:
				if a1 == a2 or a1 * i == a2 or a1 + (b2 - b1 * i) == a2:
					return True
		except:
			n = 0
		try:
			if c2 - c1 * i == a2 - a1 * i:
				if b1 == b2 or b1 * i == b2 or b1 + (c2 - c1 * i) == b2:
					return True
		except:
			n = 0
		i += 1
	i = 0
	while downCurrent < 2:
		if i < down1 and status1[0] == False:
			downCurrent += 1
			status1[0] = True
		if i < down2 and status1[1] == False:
			downCurrent += 1
			status1[1] = True
		if i < down3 and status1[2] == False:
			downCurrent += 1
			status1[2] = True
		try:
			if a2 - a1 * i == b2 - b1 * i == c2 - c1 * i:
				return True
		except:
			n = 0
		try:
			if a2 - a1 * i == b2 - b1 * i:
				if c1 == c2 or c1 * i == c2 or c1 + (a2 - a1 * i) == c2:
					return True
		except:
			n = 0
		try:
			if b2 - b1 * i == c2 - c1 * i:
				if a1 == a2 or a1 * i == a2 or a1 + (b2 - b1 * i) == a2:
					return True
		except:
			n = 0
		try:
			if c2 - c1 * i == a2 - a1 * i:
				if b1 == b2 or b1 * i == b2 or b1 + (c2 - c1 * i) == b2:
					return True
		except:
			n = 0
		i -= 1
	return False

def ifTwo(a1, b1, c1, a2, b2, c2):
	ints = []
	try:
		if a2 != b2 and a1 != b1:
			if (a2 - b2) % (a1 - b1) == 0:
				x = (a2 - b2) // (a1 - b1)
				if a2 - a1 * x == b2 - b1 * x:
					ints.append(x)
	except:
		n = 0
	try:
		if b2 != c2 and b1 != c1:
			if (b2 - c2) % (b1 - c1) == 0:
				x = (b2 - c2) // (b1 - c1)
				if b2 - b1 * x == c2 - c1 * x:
					ints.append(x)
	except:
		n = 0
	try:
		if c2 != a2 and c1 != a1:
			if (c2 - a2) % (c1 - a1) == 0:
				x = (c2 - a2) // (c1 - a1)
				if c2 - c1 * x == a2 - a1 * x:
					ints.append(x)
	except:
		n = 0
	if len(ints) == 3 and len(set(ints)) == 1:
		return True
	if len(ints) == 3 and len(set(ints)) == 2:
		return True
	if len(ints) == 3 and len(set(ints)) == 3:
		try:
			x = (a2 - b2) // (a1 - b1)
			y = a2 - a1 * x
			xx = (a1 * b2 - a2 * b1) // (a2 - b2)
			yy = a2 // (a1 + xx)
			if (a1 * b2 - a2 * b1) % (a2 - b2) != 0:
				xx = 0.4857454
				yy = 0.294823
			if c1 == c2 or c1 + y == c2 or c1 * x == c2 or (c1 + xx == c2) or (c1 * yy == c2):
				return True
		except:
			n = 0
		try:
			x = (b2 - c2) // (b1 - c1)
			y = b2 - b1 * x
			xx = (b1 * c2 - b2 * c1) // (b2 - c2)
			yy = b2 // (b1 + xx)
			if (b1 * c2 - b2 * c1) % (b2 - c2) != 0:
				xx = 0.4857454
				yy = 0.294823
			if a1 == a2 or a1 + y == a2 or a1 * x == a2 or (a1 + xx == a2) or (a1 * yy == a2):
				return True
		except:
			n = 0
		try:
			x = (c2 - a2) // (c1 - a1)
			y = c2 - c1 * x
			xx = (c1 * a2 - c2 * a1) // (c2 - a2)
			yy = c2 // (c1 + xx)
			if (c1 * a2 - c2 * a1) % (c2 - a2) != 0:
				xx = 0.4857454
				yy = 0.294823
			if b1 == b2 or b1 + y == b2 or b1 * x == b2 or (b1 + xx == b2) or (b1 * yy == b2):
				return True
		except:
			n = 0
	if len(ints) == 2 and len(set(ints)) == 1:
		return True
	if len(ints) == 2 and len(set(ints)) == 2 or len(ints) == 1:
		try:
			if a2 != b2 and a1 != b1:
				if (a2 - b2) % (a1 - b1) == 0:
					x = (a2 - b2) // (a1 - b1)
					if a2 - a1 * x == b2 - b1 * x:
						y = a2 - a1 * x
						xx = (a1 * b2 - a2 * b1) // (a2 - b2)
						yy = a2 // (a1 + xx)
						if (a1 * b2 - a2 * b1) % (a2 - b2) != 0:
							xx = 0.4857454
							yy = 0.294823
						if c1 == c2 or c1 + y == c2 or c1 * x == c2 or (c1 + xx == c2) or (c1 * yy == c2):
							return True
		except:
			n = 0
		try:
			if b2 != c2 and b1 != c1:
				if (b2 - c2) % (b1 - c1) == 0:
					x = (b2 - c2) // (b1 - c1)
					if b2 - b1 * x == c2 - c1 * x:
						y = b2 - b1 * x
						xx = (b1 * c2 - b2 * c1) // (b2 - c2)
						yy = b2 // (b1 + xx)
						if (b1 * c2 - b2 * c1) % (b2 - c2) != 0:
							xx = 0.4857454
							yy = 0.294823
						if a1 == a2 or a1 + y == a2 or a1 * x == a2 or (a1 + xx == a2) or (a1 * yy == a2):
							return True
		except:
			n = 0
		try:
			if c2 != a2 and c1 != a1:
				if (c2 - a2) % (c1 - a1) == 0:
					x = (c2 - a2) // (c1 - a1)
					if c2 - c1 * x == a2 - a1 * x:
						y = c2 - c1 * x
						xx = (c1 * a2 - c2 * a1) // (c2 - a2)
						yy = c2 // (c1 + xx)
						if (c1 * a2 - c2 * a1) % (c2 - a2) != 0:
							xx = 0.4857454
							yy = 0.294823
						if b1 == b2 or b1 + y == b2 or b1 * x == b2 or (b1 + xx == b2) or (b1 * yy == b2):
							return True
		except:
			n = 0
	return False

def ifGrid(a1, b1, c1, a2, b2, c2):
	l = [[None, None, None], [None, None, None]]
	l[0][0] = a2 - a1
	l[0][1] = b2 - b1
	l[0][2] = c2 - c1
	try:
		if a2 % a1 == 0:
			l[1][0] = a2 // a1
	except:
		n = 0
	try:
		if b2 % b1 == 0:
			l[1][1] = b2 // b1
	except:
		n = 0
	try:
		if c2 % c1 == 0:
			l[1][2] = c2 // c1
	except:
		n = 0
	if l[0][1] != None and l[1][2] != None:
		if (a1 + l[0][1]) * l[1][2] == a2 or l[0][1] + a1 * l[1][2] == a2:
			return True
	if l[0][2] != None and l[1][1] != None:
		if (a1 + l[0][2]) * l[1][1] == a2 or l[0][2] + a1 * l[1][1] == a2:
			return True
	if l[0][0] != None and l[1][2] != None:
		if (b1 + l[0][0]) * l[1][2] == b2 or l[0][0] + b1 * l[1][2] == b2:
			return True
	if l[0][2] != None and l[1][0] != None:
		if (b1 + l[0][2]) * l[1][0] == b2 or l[0][2] + b1 * l[1][0] == b2:
			return True
	if l[0][0] != None and l[1][1] != None:
		if (c1 + l[0][0]) * l[1][1] == c2 or l[0][0] + c1 * l[1][1] == c2:
			return True
	if l[0][1] != None and l[1][0] != None:
		if (c1 + l[0][1]) * l[1][0] == c2 or l[0][1] + c1 * l[1][0] == c2:
			return True
	return False
t = int(input())
while t:
	t -= 1
	(a1, b1, c1) = map(int, input().split())
	(a2, b2, c2) = map(int, input().split())
	ones = 0
	zeros = 0
	x = a2 - a1
	y = b2 - b1
	z = c2 - c1
	try:
		if a2 % a1 == 0:
			x2 = a2 // a1
		else:
			x2 = 8.12248952
	except:
		x2 = 8.12248952
	try:
		if b2 % b1 == 0:
			y2 = b2 // b1
		else:
			y2 = 43.82248952
	except:
		y2 = 43.82248952
	try:
		if c2 % c1 == 0:
			z2 = c2 // c1
		else:
			z2 = 3.81118952
	except:
		z2 = 3.81118952
	same = 0
	if a1 == a2:
		same += 1
	if b1 == b2:
		same += 1
	if c1 == c2:
		same += 1
	if same == 3:
		print(0)
	elif same == 2:
		print(1)
	elif same == 1 and (x == y or y == z or z == x):
		print(1)
	elif same == 1 and (x2 == y2 and math.ceil(x2) == x2 or (y2 == z2 and math.ceil(y2) == y2) or (z2 == x2 and math.ceil(x2) == x2)):
		print(1)
	elif same == 0 and x == y == z:
		print(1)
	elif same == 0 and (x2 == y2 == z2 and math.ceil(x2) == x2):
		print(1)
	elif a2 == b2 == c2 == 0:
		print(1)
	elif a2 == b2 == 0 and c1 == c2:
		print(1)
	elif b2 == c2 == 0 and a1 == a2:
		print(1)
	elif c2 == a2 == 0 and b1 == b2:
		print(1)
	elif ifTwo(a1, b1, c1, a2, b2, c2) or ifCombo(x, y, z, x2, y2, z2) or ifDeno(a1, b1, c1, a2, b2, c2) or ifGrid(a1, b1, c1, a2, b2, c2):
		print(2)
	elif same == 1 and a1 == a2 and (y != z):
		print(2)
	elif same == 1 and b1 == b2 and (x != z):
		print(2)
	elif same == 1 and c1 == c2 and (x != y):
		print(2)
	elif same == 0 and (x == y or y == z or z == x):
		print(2)
	elif same == 1 and a1 == a2 and (y2 != z2 or math.ceil(y2) != y2):
		print(2)
	elif same == 1 and b1 == b2 and (x2 != z2 or math.ceil(x2) != x2):
		print(2)
	elif same == 1 and c1 == c2 and (x2 != y2 or math.ceil(x2) != x2):
		print(2)
	elif same == 0 and (x2 == y2 and math.ceil(x2) == x2 or (y2 == z2 and math.ceil(y2) == y2) or (z2 == x2 and math.ceil(x2) == x2)):
		print(2)
	else:
		print(3)


def util(x1, x2, y1, y2):
	d = x1 - y1
	n = x2 - y2
	if d and (not n % d):
		return n // d
	return 1

def solve(p, q, r, a, b, c, res=0):
	if p == a and q == b and (r == c):
		return res
	if res >= 2:
		return 3
	adds = [a - p, b - q, c - r]
	muls = []
	if p and (not a % p):
		muls += [a // p]
	if q and (not b % q):
		muls += [b // q]
	if r and (not c % r):
		muls += [c // r]
	muls.append(util(p, a, q, b))
	muls.append(util(p, a, r, c))
	muls.append(util(q, b, r, c))
	mask = 2 ** 3
	ans = 3
	for msk in range(1, mask):
		for add in adds:
			(np, nq, nr) = (p, q, r)
			if msk & 1:
				np += add
			if msk & 2:
				nq += add
			if msk & 4:
				nr += add
			ans = min(ans, solve(np, nq, nr, a, b, c, res + 1))
		for mul in muls:
			(np, nq, nr) = (p, q, r)
			if msk & 1:
				np *= mul
			if msk & 2:
				nq *= mul
			if msk & 4:
				nr *= mul
			ans = min(ans, solve(np, nq, nr, a, b, c, res + 1))
	return ans

def main():
	t = int(input())
	for i in range(t):
		(p, q, r) = map(int, input().split())
		(a, b, c) = map(int, input().split())
		print(solve(p, q, r, a, b, c))
main()


def eq_solve(v0, v1, u0, u1):
	den = u0 - v0
	num = u1 - v1
	if den != 0:
		return num // den
	return 1

def solve(p, q, r, a, b, c, rs):
	if p == a and q == b and (r == c):
		return rs
	if rs >= 2:
		return 3
	res = 3
	adds = [a - p, b - q, c - r]
	muls = []
	if p != 0:
		muls.append(a // p)
	if q != 0:
		muls.append(b // q)
	if r != 0:
		muls.append(c // r)
	muls.append(eq_solve(p, a, q, b))
	muls.append(eq_solve(p, a, r, c))
	muls.append(eq_solve(q, b, r, c))
	msks = 2 ** 3
	for msk in range(msks):
		for add in adds:
			np = p
			nq = q
			nr = r
			if msk & 1 > 0:
				np += add
			if msk & 2 > 0:
				nq += add
			if msk & 4 > 0:
				nr += add
			res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
		for mul in muls:
			np = p
			nq = q
			nr = r
			if msk & 1 > 0:
				np *= mul
			if msk & 2 > 0:
				nq *= mul
			if msk & 4 > 0:
				nr *= mul
			res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
	return res
t = int(input())
while t > 0:
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	print(solve(p, q, r, a, b, c, 0))
	t -= 1


import math

def is_valid_integers(*values):
	infinity = float('inf')
	for val in values:
		if val == infinity:
			return False
		elif math.ceil(val) != math.floor(val):
			return False
	return True

def get_int_or_infinity(val):
	if is_valid_integers(val):
		return int(val)
	return float('inf')
t = int(input())

def is_zero_step_possible(p, q, r, a, b, c):
	if a == p and q == b and (c == r):
		return True
	return False

def check_for_possible_one_step(p, q, r, a, b, c):
	first_array = [(p, q, r), (q, r, p), (r, p, q), (q, p, r), (p, r, q), (r, q, p)]
	second_array = [(a, b, c), (b, c, a), (c, a, b), (b, a, c), (a, c, b), (c, b, a)]
	for i in range(0, 6):
		first = first_array[i]
		second = second_array[i]
		if is_one_step_possible(*first, *second):
			return True
	return False

def is_one_step_possible(p, q, r, a, b, c):
	d1 = a - p
	d2 = b - q
	d3 = c - r
	if d1 == d2 and d2 == d3:
		return True
	if d1 == d2 and d3 == 0:
		return True
	if d1 == d3 and d2 == 0:
		return True
	if d2 == d3 and d1 == 0:
		return True
	if d1 == d2 and d1 == 0 and d3:
		return True
	if d2 == d3 and d2 == 0 and d1:
		return True
	if d1 == d3 and d1 == 0 and d2:
		return True
	try:
		m1 = get_int_or_infinity(a / p)
	except:
		m1 = float('inf')
	try:
		m2 = get_int_or_infinity(b / q)
	except:
		m2 = float('inf')
	try:
		m3 = get_int_or_infinity(c / r)
	except:
		m3 = float('inf')
	if is_valid_integers(m1, m2, m3):
		if m1 == m2 and m2 == m3:
			return True
		if m1 == m2 and m3 == 1:
			return True
		if m1 == m3 and m2 == 1:
			return True
		if m2 == m3 and m1 == 1:
			return True
	if is_valid_integers(m1, m2) and m1 == m2 and (c == r):
		return True
	if is_valid_integers(m2, m3) and m2 == m3 and (a == p):
		return True
	if is_valid_integers(m1, m3) and m1 == m3 and (b == q):
		return True
	return False

def get_m_and_d_for_mul_and_add_step(p, q, a, b):
	try:
		m = get_int_or_infinity((a - b) / (p - q))
	except:
		m = float('inf')
	try:
		d = get_int_or_infinity((p * b - q * a) / (p - q))
	except:
		d = float('inf')
	return (m, d)

def multiply_and_add_step(p, q, r, a, b, c):
	infinity = float('inf')
	(m1, d1) = get_m_and_d_for_mul_and_add_step(p, q, a, b)
	(m2, d2) = get_m_and_d_for_mul_and_add_step(p, r, a, c)
	if is_valid_integers(m1, d1, m2, d2) and m1 == m2 and (d1 == d2):
		return True
	try:
		m3 = get_int_or_infinity(c / r)
	except:
		m3 = infinity
	if is_valid_integers(m3) and a - p * m3 == b - q * m3:
		return True
	try:
		m4 = get_int_or_infinity(b / q)
		m5 = get_int_or_infinity(c / r)
	except:
		m4 = infinity
		m5 = infinity
	if is_valid_integers(m4, m5) and m4 == m5 and a - p * m5:
		return True
	d6 = c - r
	try:
		m6 = get_int_or_infinity((a - d6) / p)
		m7 = get_int_or_infinity((b - d6) / q)
	except:
		m6 = infinity
		m7 = infinity
	if is_valid_integers(m6, m7) and m6 == m7 and d6:
		return True
	if r == c:
		try:
			m8 = get_int_or_infinity((a - b) / (p - q))
		except:
			m8 = infinity
		if is_valid_integers(m8) and a - p * m8 == b - q * m8 and a - p * m8:
			return True
	d9 = c - r
	try:
		m9 = get_int_or_infinity(b / q)
	except:
		m9 = infinity
	if is_valid_integers(m9) and p * m9 + d9 == a:
		return True
	if c == r:
		try:
			m10 = get_int_or_infinity(b / q)
		except:
			m10 = infinity
		if is_valid_integers(m10) and a - p * m10 and (b == q * m10):
			return True
	if c - r:
		try:
			m11 = get_int_or_infinity(a / p)
			m12 = get_int_or_infinity(b / q)
		except:
			m11 = infinity
			m12 = infinity
		if is_valid_integers(m11, m12) and m11 == m12:
			return True
	if c - r and a == p:
		try:
			m13 = get_int_or_infinity(b / q)
		except:
			m13 = infinity
		if is_valid_integers(m13):
			return True
	if c - r and a == p:
		d14 = c - r
		try:
			m14 = get_int_or_infinity((b - d14) / q)
		except:
			m14 = infinity
		if is_valid_integers(m14):
			return True
	if c - r and c - r == a - p:
		try:
			m15 = get_int_or_infinity(b / q)
		except:
			m15 = infinity
		if is_valid_integers(m15):
			return True
	if c - r and c - r == a - p:
		d = c - r
		try:
			m16 = get_int_or_infinity((b - d) / q)
		except:
			m16 = infinity
		if is_valid_integers(m16):
			return True
	return False

def add_and_multiply_step(p, q, r, a, b, c):
	infinity = float('inf')
	try:
		m1 = get_int_or_infinity((a - b) / (p - q))
	except:
		m1 = infinity
	try:
		m2 = get_int_or_infinity((b - c) / (q - r))
	except:
		m2 = infinity
	if is_valid_integers(m1, m2) and m1 == m2:
		try:
			d = get_int_or_infinity((a - p * m1) / m1)
		except:
			d = infinity
		if is_valid_integers(d) and b == q * m1 + d * m1:
			return True
	if c - r:
		d = c - r
		try:
			m1 = get_int_or_infinity((a - b) / (p - q))
		except:
			m1 = infinity
		if is_valid_integers(m1) and a == p * m1 + d * m1 and (b == q * m1 + d * m1):
			return True
	if c - r and c - r == b - q:
		d = c - r
		try:
			m1 = get_int_or_infinity(a / (p + d))
		except:
			m1 = infinity
		if is_valid_integers(m1):
			return True
	try:
		m1 = get_int_or_infinity(c / r)
		m2 = get_int_or_infinity((a - b) / (p - q))
	except:
		m1 = infinity
		m2 = infinity
	if is_valid_integers(m1, m2) and m1 == m2:
		try:
			d = get_int_or_infinity((a - p * m1) / m1)
		except:
			d = infinity
		if is_valid_integers(d) and b == q * m1 + d * m1:
			return True
	d = b - q
	if d:
		try:
			m1 = get_int_or_infinity(c / r)
		except:
			m1 = infinity
		if is_valid_integers(m1) and a == p * m1 + d * m1:
			return True
	if c == r:
		try:
			m1 = get_int_or_infinity((a - b) / (p - q))
		except:
			m1 = infinity
		if is_valid_integers(m1):
			try:
				d = get_int_or_infinity((a - p * m1) / m1)
			except:
				d = infinity
			if is_valid_integers(d) and b == q * m1 + d * m1:
				return True
	try:
		m = get_int_or_infinity(c / r)
	except:
		m = infinity
	if is_valid_integers(m) and a - p == b - q:
		return True
	if c == r and b - q:
		d = b - q
		try:
			m = get_int_or_infinity(a / (p + d))
		except:
			m = infinity
		if is_valid_integers(m):
			return True
	try:
		m1 = get_int_or_infinity(b / q)
		m2 = get_int_or_infinity(c / r)
	except:
		m1 = infinity
		m2 = infinity
		if is_valid_integers(m1, m2) and m1 == m2:
			try:
				d = get_int_or_infinity((a - p * m1) / m1)
			except:
				d = infinity
			if is_valid_integers(d):
				return True
	if c == r:
		try:
			m = get_int_or_infinity(b / q)
		except:
			m = infinity
		if is_valid_integers(m):
			try:
				d = get_int_or_infinity((a - p * m) / m)
			except:
				d = infinity
			if is_valid_integers(d):
				return True
	try:
		m1 = get_int_or_infinity(b / q)
		m2 = get_int_or_infinity(c / r)
	except:
		m1 = infinity
		m2 = infinity
	if is_valid_integers(m1, m2) and m1 == m2 and a - p:
		return True
	if c == r:
		try:
			m = get_int_or_infinity(b / q)
		except:
			m = infinity
		if is_valid_integers(m) and a - p:
			return True
	return False

def get_d_and_m_for_add_and_mul_step(p, q, a, b):
	try:
		m = get_int_or_infinity((a - b) / (p - q))
	except:
		m = float('inf')
	try:
		d = get_int_or_infinity((p * b - q * a) / (a - b))
	except:
		d = float('inf')
	return (d, m)

def add_and_add_step(p, q, r, a, b, c):
	d1 = c - r
	if d1 and a - p - d1 == b - q - d1:
		return True
	if c - r == b - q and a - p - b + q:
		return True
	d1 = a - p
	d2 = b - q - d1
	if c - r == d2:
		return True
	if c - r == b - q and c - r and a - p:
		return True
	if c == r and b - q and a - p + q - b:
		return True
	if b - q == c - r and b - q and a - p + q - b:
		return True

def mul_and_mul_step(p, q, r, a, b, c):
	infinity = float('inf')
	try:
		m1 = get_int_or_infinity(a / p)
	except:
		m1 = infinity
	try:
		if m1 != infinity:
			m2 = get_int_or_infinity(c / (r * m1))
		else:
			m2 = infinity
	except:
		m2 = infinity
	if is_valid_integers(m1, m2) and b == q * m1:
		return True
	try:
		m1 = get_int_or_infinity(c / r)
	except:
		m1 = infinity
	try:
		if m1 != infinity:
			m2 = get_int_or_infinity(a / (p * m1))
		else:
			m2 = infinity
	except:
		m2 = infinity
	if is_valid_integers(m1, m2) and b == q * m1 * m2:
		return True
	try:
		m2 = get_int_or_infinity(a / p)
	except:
		m2 = infinity
	try:
		if m2 != infinity:
			m1 = get_int_or_infinity(c / (r * m2))
		else:
			m1 = infinity
	except:
		m1 = infinity
	if is_valid_integers(m1, m2) and q * m1 == b:
		return True
	try:
		m1 = get_int_or_infinity(a / p)
	except:
		m1 = infinity
	try:
		m2 = get_int_or_infinity(c / r)
	except:
		m2 = infinity
	if is_valid_integers(m1, m2) and q * m1 == b:
		return True
	if c == r:
		try:
			m1 = get_int_or_infinity(a / p)
		except:
			m1 = infinity
		try:
			if m1 != infinity:
				m2 = get_int_or_infinity(b / (q * m1))
			else:
				m2 = infinity
		except:
			m2 = infinity
		if is_valid_integers(m1, m2):
			return True
	return False

def is_two_step_possible(p, q, r, a, b, c):
	first_array = [(p, q, r), (q, r, p), (r, p, q), (q, p, r), (p, r, q), (r, q, p)]
	second_array = [(a, b, c), (b, c, a), (c, a, b), (b, a, c), (a, c, b), (c, b, a)]
	for i in range(0, 6):
		first = first_array[i]
		second = second_array[i]
		if multiply_and_add_step(*first, *second):
			return True
		if add_and_multiply_step(*first, *second):
			return True
		if mul_and_mul_step(*first, *second):
			return True
		if add_and_add_step(*first, *second):
			return True
	return False
while t > 0:
	t -= 1
	(p, q, r) = list(map(int, input().split(' ')))
	(a, b, c) = list(map(int, input().split(' ')))
	if is_zero_step_possible(p, q, r, a, b, c):
		print(0)
	elif check_for_possible_one_step(p, q, r, a, b, c):
		print(1)
	elif is_two_step_possible(p, q, r, a, b, c):
		print(2)
	else:
		print(3)


from sys import stdin

def Coincide(p, a, q, b, r, c):
	x = b - a
	d = q - p
	if d != 0:
		y = a - 1 * p * (x / d)
		if 1 * r * (x / d) + y == c:
			if x % d == 0:
				return True
		if x % d == 0 and r + y == c:
			return True
		if x % d == 0 and r * x == c:
			return True
	return False

def check2(p, a, q, b):
	if p == a or q == b:
		return True
	if a - p == b - q:
		return True
	if p != 0 and q != 0 and (a % p == 0) and (b % q == 0) and (a / p == b / q):
		return True
	return False
t = int(input())
for _ in range(t):
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	if p == a and q == b and (r == c):
		print(0)
		continue
	if p == a and check2(q, b, r, c) or (q == b and check2(p, a, r, c)) or (r == c and check2(q, b, p, a)):
		print(1)
		continue
	diff = a - p
	if q + diff == b and r + diff == c:
		print(1)
		continue
	if p != 0 and a % p == 0:
		diff = a / p
		if q * diff == b and r * diff == c:
			print(1)
			continue
	d = 0
	if p != 0 and a % p == 0:
		d = a / p
		if check2(q * d, b, r * d, c) or check2(q * d, b, r, c) or check2(q, b, r * d, c) or check2(q, b, r, c):
			print(2)
			continue
	d = a - p
	if check2(q + d, b, r + d, c) or check2(q + d, b, r, c) or check2(q, b, r + d, c) or check2(q, b, r, c):
		print(2)
		continue
	if q != 0 and b % q == 0:
		d = b / q
		if check2(p * d, a, r * d, c) or check2(p * d, a, r, c) or check2(p, a, r * d, c) or check2(p, a, r, c):
			print(2)
			continue
	d = b - q
	if check2(p + d, a, r + d, c) or check2(p + d, a, r, c) or check2(p, a, r + d, c) or check2(p, a, r, c):
		print(2)
		continue
	if r != 0 and c % r == 0:
		d = c / r
		if check2(q * d, b, p * d, a) or check2(q * d, b, p, a) or check2(q, b, p * d, a) or check2(q, b, p, a):
			print(2)
			continue
	d = c - r
	if check2(q + d, b, p + d, a) or check2(q + d, b, p, a) or check2(q, b, p + d, a) or check2(q, b, p, a):
		print(2)
		continue
	if Coincide(p, a, q, b, r, c) or Coincide(p, a, r, c, q, b) or Coincide(q, b, r, c, p, a):
		print(2)
		continue
	print(3)


import math
all_fact = set()

def factorize(num):
	numr = int(math.sqrt(abs(num)))
	for i in range(1, numr + 1):
		if num % i == 0:
			all_fact.add(i)
			all_fact.add(-i)
			all_fact.add(num // i)
			all_fact.add(-num // i)

def pro_sum(a, b, c, p, q, r):
	for i in all_fact:
		dif1 = 0
		if p % i != 0:
			dif1 = p - a
		else:
			dif1 = p // i - a
		if q == b or q - dif1 == b or (q % i == 0 and q // i == b) or (q % i == 0 and q // i - dif1 == b):
			if r == c or r - dif1 == c or (r % i == 0 and r // i == c) or (r % i == 0 and r // i - dif1 == c):
				return 2
	return 3

def sum_sum_pro(a, b, c, p, q, r):
	d = p - a
	if b != 0 and q % b == 0:
		k = q // b
		if c * k == r or c * k + d == r or c + d == r or ((c + d) * k == r):
			return 2
	if b != 0 and (q - d) % b == 0:
		k = (q - d) // b
		if c * k == r or c * k + d == r or c + d == r:
			return 2
	return 3

def sum_pro(a, b, c, p, q, r):
	a1 = a - b
	dif1 = p - q
	if a1 != 0:
		if dif1 % a1 == 0:
			k = dif1 // a1
			d = p - k * a
			if (c * k + d == r or c + d == r or c * k == r) and (b * k + d == q or b + d == q or b * k == q):
				return 2
			d = q - k * b
			if (c * k + d == r or c + d == r or c * k == r) and (a * k + d == p or a + d == p or a * k == p):
				return 2
	return 3

def this_one_for_SSR():
	(a, b, c) = map(int, input().split(' '))
	(p, q, r) = map(int, input().split(' '))
	if a == p and b == q and (c == r):
		print('0')
		return
	dif1 = p - a
	dif2 = q - b
	dif3 = r - c
	if (p - a == 0 or p - a == dif1) and (q - b == 0 or q - b == dif1) and (r - c == 0 or r - c == dif1):
		print('1')
		return
	elif (p - a == 0 or p - a == dif2) and (q - b == 0 or q - b == dif2) and (r - c == 0 or r - c == dif2):
		print('1')
		return
	elif (p - a == 0 or p - a == dif3) and (q - b == 0 or q - b == dif3) and (r - c == 0 or r - c == dif3):
		print('1')
		return
	if (b == q or (a != 0 and b != 0 and (q % b == 0) and (p % a == 0) and (p // a == q // b))) and (r == c or (a != 0 and c != 0 and (r % c == 0) and (p % a == 0) and (p // a == r // c))):
		print('1')
		return
	elif (a == p or (a != 0 and b != 0 and (q % b == 0) and (p % a == 0) and (p // a == q // b))) and (r == c or (b != 0 and c != 0 and (r % c == 0) and (q % b == 0) and (q // b == r // c))):
		print('1')
		return
	elif (b == q or (c != 0 and b != 0 and (q % b == 0) and (r % c == 0) and (r // c == q // b))) and (r == c or (a != 0 and c != 0 and (r % c == 0) and (p % a == 0) and (p // a == r // c))):
		print('1')
		return
	if dif1 == dif2 or dif2 == dif3 or dif1 == dif3 or (dif1 + dif2 == dif3) or (dif2 + dif3 == dif1) or (dif1 + dif3 == dif2) or (dif1 == 0) or (dif2 == 0) or (dif3 == 0):
		print('2')
		return
	if a != 0 and b != 0 and (c != 0) and (p % a == 0) and (q % b == 0) and (r % c == 0):
		x = p / a
		y = q / b
		z = r / c
		if x * y == z or z * x == y or y * z == x:
			print('2')
			return
	all_fact.clear()
	factorize(p)
	factorize(q)
	factorize(r)
	mini = 3
	mini = min(mini, pro_sum(a, b, c, p, q, r))
	mini = min(mini, pro_sum(a, c, b, p, r, q))
	mini = min(mini, sum_pro(a, b, c, p, q, r))
	mini = min(mini, sum_pro(a, c, b, p, r, q))
	mini = min(mini, sum_sum_pro(a, b, c, p, q, r))
	mini = min(mini, sum_sum_pro(a, c, b, p, r, q))
	mini = min(mini, pro_sum(b, a, c, q, p, r))
	mini = min(mini, pro_sum(b, c, a, q, r, p))
	mini = min(mini, sum_pro(b, c, a, q, r, p))
	mini = min(mini, sum_pro(b, a, c, q, p, r))
	mini = min(mini, sum_sum_pro(b, c, a, q, r, p))
	mini = min(mini, sum_sum_pro(b, a, c, q, p, r))
	mini = min(mini, pro_sum(c, a, b, r, p, q))
	mini = min(mini, pro_sum(c, b, a, r, q, p))
	mini = min(mini, sum_pro(c, a, b, r, p, q))
	mini = min(mini, sum_pro(c, b, a, r, q, p))
	mini = min(mini, sum_sum_pro(c, a, b, r, p, q))
	mini = min(mini, sum_sum_pro(c, b, a, r, q, p))
	print(mini)
	return
t = int(input())
while t > 0:
	t -= 1
	this_one_for_SSR()


import math

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def binR(a, i):
	vd = 100
	har = 200
	kite = 300
	kot = 400
	v = [[0, 0], [0, 0], [0, 0]]
	if i < 8:
		nm = i
		for k in range(3):
			v[k][0] = a[k]
			v[k][1] = 0
			if nm % 2 != 0:
				v[k][1] = 1
			nm = nm // 2
	else:
		nm = i % 7
		if nm == 0:
			nm = 7
		for k in range(3):
			if nm % 2 != 0:
				v[k][0] = 0
				v[k][1] = a[k]
			else:
				v[k][0] = a[k]
				v[k][1] = 0
			nm = nm // 2
	vd = 100
	har = 200
	kite = 300
	kot = 400
	return v

def single(a, b):
	d = 0
	p = 1
	vd = 100
	har = 200
	kite = 300
	kot = 400
	md = 10 ** 9 + 7
	diff = [0, 0, 0]
	pod = [md, md, md]
	for i in range(3):
		diff[i] = b[i] - a[i]
		if d == 0:
			d = diff[i]
		if diff[i] == 0:
			pod[i] = 1
		elif a[i] != 0:
			if b[i] % a[i] == 0:
				pod[i] = b[i] / a[i]
				p = pod[i]
	i = 0
	while i != 3:
		if diff[i] == 0 or diff[i] == d:
			vd = 100
			har = 200
			kite = 300
			kot = 400
			i += 1
		else:
			break
	if i == 3:
		return 1
	i = 0
	while i != 3:
		if pod[i] == 1 or pod[i] == p:
			i += 1
		else:
			break
	if i == 3:
		return 1
	vd = 100
	har = 200
	kite = 300
	kot = 400
	return 3

def bfill(b, j):
	vd = 100
	har = 200
	kite = 300
	kot = 400
	k = 0
	for i in range(3):
		if j % 2 != 0:
			if k == 0:
				k = b[i]
			else:
				k = gcd(k, b[i])
		j = j // 2
	return k

def bfill2(j, b, r):
	c = [0, 0, 0]
	vd = 100
	har = 200
	kite = 300
	kot = 400
	for i in range(3):
		if j % 2 != 0:
			c[i] = b[i] / r
		else:
			c[i] = b[i]
		j = j // 2
	return c

def find(v1, v2, kk, a):
	den1 = 0
	den2 = 0
	u_n = 0
	vd = 100
	har = 200
	kite = 300
	kot = 400
	my1 = gcd(v1[0][1], v1[1][1])
	my1 = gcd(v1[2][1], my1)
	my2 = gcd(v2[0][1], v2[1][1])
	my2 = gcd(v2[2][1], my2)
	vd = 100
	har = 200
	kite = 300
	kot = 400
	if my1 == 0:
		my1 = 1
	if my2 == 0:
		my2 = 1
	for k in range(3):
		v1[k][1] = v1[k][1] // my1
		v2[k][1] = v2[k][1] // my2
	vd = 100
	har = 200
	kite = 300
	kot = 400
	for k in range(3):
		den1 += v1[k][1] ** 2
		den2 += v2[k][1] ** 2
		u_n += v1[k][1] * v2[k][1]
	u_d = den1 * den2
	if u_n ** 2 == u_d:
		return 3
	t1 = 0
	t2 = 0
	for k in range(3):
		t1 += (v2[k][0] - v1[k][0]) * v1[k][1]
		t2 += (v2[k][0] - v1[k][0]) * v2[k][1]
	if u_d == 0:
		return 3
	s1 = den2 * t1 - u_n * t2
	s2 = u_d - u_n ** 2
	s22 = 0 - s2
	gc1 = gcd(abs(s1), abs(s2))
	if gc1 != 0 and s1 != 0 and (s2 != 0):
		s1 = s1 // gc1
		s2 = s2 // gc1
	vd = 100
	har = 200
	kite = 300
	kot = 400
	s11 = t2 * den1 - u_n * t1
	gc1 = gcd(abs(s11), abs(s22))
	if gc1 != 0 and s11 != 0 and (s22 != 0):
		s11 = s11 // gc1
		s22 = s22 // gc1
	if s2 == 0 or s22 == 0:
		return 3
	p = [0, 0, 0]
	for k in range(3):
		if s1 * v1[k][1] % s2 != 0:
			return 3
		p1 = v1[k][0] + s1 * v1[k][1] // s2
		if s11 * v2[k][1] % s22 != 0:
			return 3
		p2 = v2[k][0] + s11 * v2[k][1] // s22
		if p1 != p2:
			return 3
		p[k] = p1
	vd = 100
	har = 200
	kite = 300
	kot = 400
	if kk == 1:
		for i in range(3):
			if p[i] % a[i] != 0:
				return 3
	return 2

def call():
	a = []
	a = list(map(int, input().split()))
	b = []
	b = list(map(int, input().split()))
	if a[0] == b[0] and a[1] == b[1] and (a[2] == b[2]):
		return 0
	vd = 100
	har = 200
	kite = 300
	kot = 400
	dis = single(a, b)
	if dis == 1:
		return 1
	for j in range(1, 8):
		k = bfill(b, j)
		for i in range(2, math.ceil(abs(k) ** 0.5)):
			if abs(k) % i == 0:
				c = bfill2(j, b, i)
				if single(a, c) == 1:
					return 2
				c = bfill2(j, b, -i)
				if single(a, c) == 1:
					return 2
				ii = abs(k) // i
				if i != ii:
					c = bfill2(j, b, ii)
					if single(a, c) == 1:
						return 2
					c = bfill2(j, b, -ii)
					if single(a, c) == 1:
						vd = 100
						har = 200
						kite = 300
						kot = 400
						return 2
		if k != 0 and k != 1:
			c = bfill2(j, b, k)
			if single(a, c) == 1:
				return 2
			c = bfill2(j, b, -k)
			if single(a, c) == 1:
				return 2
		c = bfill2(j, b, -1)
		if single(a, c) == 1:
			return 2
	for i in range(1, 15):
		for j in range(1, 8):
			v1 = binR(a, i)
			v2 = binR(b, j)
			kk = 0
			if i > 7:
				kk = 1
			k = find(v1, v2, kk, a)
			vd = 100
			har = 200
			kite = 300
			kot = 400
			if k == 2:
				return 2
	return 3
t = int(input())
while t != 0:
	k = call()
	vd = 100
	har = 200
	kite = 300
	kot = 400
	print(k)
	t -= 1


for t in range(int(input())):
	(a, b, c) = map(int, input().split())
	(p, q, r) = map(int, input().split())
	x = p - a
	y = q - b
	z = r - c
	flag = 1
	if a != 0 and b != 0 and (c != 0) and (p == 0) and (q == 0) and (r == 0):
		print(1)
		flag = 0
		continue
	if x == 0 and y == 0 and (z == 0):
		print(0)
		flag = 0
		continue
	if p != 0 and q != 0 and (r != 0) and (a != 0) and (b != 0) and (c != 0):
		m = p / a
		n = q / b
		o = r / c
		if x == 0 and y == 0 and (z != 0) or (x == 0 and y != 0 and (z == 0)) or (x != 0 and y == 0 and (z == 0)) or (m == 1 and n == 1 and (o != 1)) or (m == 1 and n != 1 and (o == 1)) or (m != 1 and n == 1 and (o == 1)) or (x == 0 and y != 0 and (y == z)) or (x != 0 and y == 0 and (z == x)) or (x != 0 and y == x and (z == 0)) or (m != 1 and n == m and (o == 1)) or (m != 1 and n == 1 and (o == m)) or (m == 1 and n != 1 and (o == n)) or (x == y and y == z and (x != 0)) or (m == n and n == o and (m != 1)):
			print(1)
			flag = 0
			continue
	if p == 0 or q == 0 or r == 0 or (a == 0) or (b == 0) or (c == 0):
		if x == 0 and y == 0 and (z != 0) or (x == 0 and y != 0 and (z == 0)) or (x != 0 and y == 0 and (z == 0)) or (x == 0 and y != 0 and (y == z)) or (x != 0 and y == 0 and (z == x)) or (x != 0 and y == x and (z == 0)) or (x == y and y == z and (x != 0)):
			print(1)
			flag = 0
			continue
	if a == 0 and p == 0 and (b != 0) and (c != 0) and (q % b == 0) and (r % c == 0) and (q / b == r / c) or (b == 0 and q == 0 and (a != 0) and (c != 0) and (p % a == 0) and (r % c == 0) and (p / a == r / c)) or (c == 0 and r == 0 and (a != 0) and (b != 0) and (p % a == 0) and (q % b == 0) and (p / a == q / b)):
		print(1)
		flag = 0
		continue
	if flag != 0:
		if x + y == z or x + z == y or z + y == x or (x == y) or (y == z) or (x == z):
			print(2)
			flag = 0
			continue
		if x == 0 or z == 0 or y == 0:
			print(2)
			flag = 0
			continue
		if a != 0 and b != 0 and (c != 0):
			if p % a == 0 and q % b == 0 and (r % c == 0):
				x = p / a
				y = q / b
				z = r / c
				if x * y == z or y * z == x or z * x == y or (x == y) or (y == z) or (x == z):
					print(2)
					flag = 0
					continue
				if x == 1 or y == 1 or z == 1:
					print(2)
					flag = 0
					continue
		if p - q != 0:
			x = (a * q - b * p) / (p - q)
			if a + x != 0 and p % (a + x) == 0:
				y = p / (a + x)
				if c + x == r or c * y == r or (c + x) * y == r:
					print(2)
					flag = 0
					continue
		if q - r != 0:
			x = (b * r - c * q) / (q - r)
			if b + x != 0 and q % (b + x) == 0:
				y = q / (b + x)
				if a + x == p or a * y == p or (a + x) * y == p:
					print(2)
					flag = 0
					continue
		if r - p != 0:
			x = (c * p - a * r) / (r - p)
			if c + x != 0 and r % (c + x) == 0:
				y = r / (c + x)
				if b + x == q or b * y == q or (b + x) * y == q:
					print(2)
					flag = 0
					continue
		if a == 0 and b != 0 and (c != 0) and (p != 0) and (q != 0) and (r != 0) and (q % b == 0) and (r % c == 0) and (q / b == r / c):
			print(2)
			flag = 0
			continue
		if a != 0 and b == 0 and (c != 0) and (p != 0) and (q != 0) and (r != 0) and (p % a == 0) and (r % c == 0) and (p / a == r / c):
			print(2)
			flag = 0
			continue
		if a != 0 and b != 0 and (c == 0) and (p != 0) and (q != 0) and (r != 0) and (q % b == 0) and (p % a == 0) and (p / a == q / b):
			print(2)
			flag = 0
			continue
		if a != 0 and b != 0 and (c != 0):
			if p % a == 0 and q % b == 0 and (p / a == q / b) or (q % b == 0 and r % c == 0 and (q / b == r / c)) or (r % c == 0 and p % a == 0 and (r / c == p / a)):
				print(2)
				flag = 0
				continue
		if a - b != 0 and (p - q) % (a - b) == 0:
			x = (p - q) / (a - b)
			y = p - a * x
			if c * x == r or c + y == r or c * x + y == r:
				print(2)
				flag = 0
				continue
		if b - c != 0 and (q - r) % (b - c) == 0:
			x = (q - r) / (b - c)
			y = q - b * x
			if a * x == p or a + y == p or a * x + y == p:
				print(2)
				flag = 0
				continue
		if c - a != 0 and (r - p) % (c - a) == 0:
			x = (r - p) / (c - a)
			y = r - c * x
			if b * x == q or b + y == q or b * x + y == q:
				print(2)
				flag = 0
				continue
		if c != 0 and r % c == 0:
			if (a + q - b) * (r / c) == p or (b + p - a) * (r / c) == q or a * (r / c) + q - b == p or (b * (r / c) + p - a == q):
				print(2)
				flag = 0
				continue
		if a != 0 and p % a == 0:
			if (b + r - c) * (p / a) == q or (c + q - b) * (p / a) == r or b * (p / a) + r - c == q or (c * (p / a) + q - b == r):
				print(2)
				flag = 0
				continue
		if b != 0 and q % b == 0:
			if (a + r - c) * (q / b) == p or (c + p - a) * (q / b) == r or a * (q / b) + r - c == p or (c * (q / b) + p - a == r):
				print(2)
				flag = 0
				continue
	if flag != 0:
		print(3)
		flag = 0
		continue


for _ in range(int(input())):
	a = input().split()
	b = input().split()
	a = [int(i) for i in a]
	b = [int(i) for i in b]
	dif = [0] * 3
	if b[0] == a[0] and b[1] == a[1] and (b[2] == a[2]):
		print(0)
		continue
	dif[0] = b[0] - a[0]
	dif[1] = b[1] - a[1]
	dif[2] = b[2] - a[2]
	if dif[0] == 0 and dif[1] == 0 and (dif[2] != 0) or (dif[0] != 0 and dif[1] == 0 and (dif[2] == 0)) or (dif[0] == 0 and dif[1] != 0 and (dif[2] == 0)):
		print(1)
		continue
	if dif[0] == 0 and dif[1] != 0 and (dif[2] != 0) and (dif[1] == dif[2]) or (dif[1] == 0 and dif[2] != 0 and (dif[0] != 0) and (dif[0] == dif[2])) or (dif[2] == 0 and dif[0] != 0 and (dif[1] != 0) and (dif[0] == dif[1])):
		print(1)
		continue
	if dif[0] == 0 and dif[1] != 0 and (dif[2] != 0):
		if a[1] != 0 and a[2] != 0:
			if b[1] % a[1] == 0 and b[2] % a[2] == 0:
				if b[1] / a[1] == b[2] / a[2]:
					print(1)
					continue
	if dif[1] == 0 and dif[0] != 0 and (dif[2] != 0):
		if a[0] != 0 and a[2] != 0:
			if b[0] % a[0] == 0 and b[2] % a[2] == 0:
				if b[0] / a[0] == b[2] / a[2]:
					print(1)
					continue
	if dif[2] == 0 and dif[1] != 0 and (dif[0] != 0):
		if a[1] != 0 and a[0] != 0:
			if b[1] % a[1] == 0 and b[0] % a[0] == 0:
				if b[1] / a[1] == b[0] / a[0]:
					print(1)
					continue
	if dif[2] != 0 and dif[1] != 0 and (dif[0] != 0) and (dif[0] == dif[1]) and (dif[1] == dif[2]):
		print(1)
		continue
	if dif[2] != 0 and dif[1] != 0 and (dif[0] != 0):
		if a[0] != 0 and a[1] != 0 and (a[2] != 0):
			if b[0] % a[0] == 0 and b[1] % a[1] == 0 and (b[2] % a[2] == 0):
				if b[0] / a[0] == b[1] / a[1] == b[2] / a[2]:
					print(1)
					continue
	if dif[0] == 0 and dif[1] != dif[2] or (dif[1] == 0 and dif[2] != dif[0]) or (dif[2] == 0 and dif[0] != dif[1]):
		print(2)
		continue
	if dif[0] == 0 and a[1] != 0 and (a[2] != 0):
		if b[1] % a[1] == 0 and b[2] % a[2] == 0:
			if b[1] / a[1] != b[2] / a[2]:
				print(2)
				continue
	if dif[1] == 0 and a[0] != 0 and (a[2] != 0):
		if b[0] % a[0] == 0 and b[2] % a[2] == 0:
			if b[0] / a[0] != b[2] / a[2]:
				print(2)
				continue
	if dif[2] == 0 and a[0] != 0 and (a[1] != 0):
		if b[1] % a[1] == 0 and b[0] % a[0] == 0:
			if b[1] / a[1] != b[0] / a[0]:
				print(2)
				continue
	if dif[0] == dif[1] != dif[2] != 0 or dif[1] == dif[2] != dif[0] != 0 or dif[0] == dif[2] != dif[1] != 0:
		print(2)
		continue
	if a[0] != 0 and a[1] != 0 and (dif[0] != 0) and (dif[1] != 0) and (dif[2] != 0):
		if b[0] % a[0] == 0 and b[1] % a[1] == 0:
			if b[0] / a[0] == b[1] / a[1]:
				print(2)
				continue
	if a[0] != 0 and a[2] != 0 and (dif[0] != 0) and (dif[1] != 0) and (dif[2] != 0):
		if b[0] % a[0] == 0 and b[2] % a[2] == 0:
			if b[0] / a[0] == b[2] / a[2]:
				print(2)
				continue
	if a[2] != 0 and a[1] != 0 and (dif[0] != 0) and (dif[1] != 0) and (dif[2] != 0):
		if b[2] % a[2] == 0 and b[1] % a[1] == 0:
			if b[2] / a[2] == b[1] / a[1]:
				print(2)
				continue
	if dif[0] + dif[1] == dif[2] or dif[1] + dif[2] == dif[0] or dif[2] + dif[0] == dif[1]:
		print(2)
		continue
	if a[0] != 0 and a[1] != 0 and (a[2] != 0):
		if b[0] % a[0] == 0 and b[1] % a[1] == 0 and (b[2] % a[2] == 0):
			if b[0] / a[0] * (b[1] / a[1]) == b[2] / a[2] or b[0] / a[0] * (b[2] / a[2]) == b[1] / a[1] or b[2] / a[2] * (b[1] / a[1]) == b[0] / a[0]:
				print(2)
				continue
	if a[1] != 0:
		if b[1] % a[1] == 0 and (a[2] * (b[1] / a[1]) + dif[0] == b[2] or (a[2] + dif[0]) * (b[1] / a[1]) == b[2]):
			print(2)
			continue
	if a[1] != 0:
		if b[1] % a[1] == 0 and (a[0] * (b[1] / a[1]) + dif[2] == b[0] or (a[0] + dif[2]) * (b[1] / a[1]) == b[0]):
			print(2)
			continue
	if a[0] != 0:
		if b[0] % a[0] == 0 and (a[2] * (b[0] / a[0]) + dif[1] == b[2] or (a[2] + dif[1]) * (b[0] / a[0]) == b[2]):
			print(2)
			continue
	if a[0] != 0:
		if b[0] % a[0] == 0 and (a[1] * (b[0] / a[0]) + dif[2] == b[1] or (a[1] + dif[2]) * (b[0] / a[0]) == b[1]):
			print(2)
			continue
	if a[2] != 0:
		if b[2] % a[2] == 0 and (a[1] * (b[2] / a[2]) + dif[0] == b[1] or (a[1] + dif[0]) * (b[2] / a[2]) == b[1]):
			print(2)
			continue
	if a[2] != 0:
		if b[2] % a[2] == 0 and (a[0] * (b[2] / a[2]) + dif[1] == b[0] or (a[0] + dif[1]) * (b[2] / a[2]) == b[0]):
			print(2)
			continue
	if a[0] - a[1] != 0 and b[0] - b[1] != 0:
		if (b[0] - b[1]) % (a[0] - a[1]) == 0:
			x = (b[0] - b[1]) / (a[0] - a[1])
			if (a[0] * b[1] - b[0] * a[1]) % (b[0] - b[1]) == 0:
				y = (a[0] * b[1] - b[0] * a[1]) / (b[0] - b[1])
				if (a[0] + y) * x == b[0] and (a[1] + y) * x == b[1] and (a[2] + y == b[2] or a[2] * x == b[2] or (a[2] + y) * x == b[2]):
					print(2)
					continue
	if a[0] - a[2] != 0 and b[0] - b[2] != 0:
		if (b[0] - b[2]) % (a[0] - a[2]) == 0:
			x = (b[0] - b[2]) / (a[0] - a[2])
			if (a[0] * b[2] - b[0] * a[2]) % (b[0] - b[2]) == 0:
				y = (a[0] * b[2] - b[0] * a[2]) / (b[0] - b[2])
				if (a[0] + y) * x == b[0] and (a[2] + y) * x == b[2] and (a[1] + y == b[1] or a[1] * x == b[1] or (a[1] + y) * x == b[1]):
					print(2)
					continue
	if a[1] - a[2] != 0 and b[1] - b[2] != 0:
		if (b[1] - b[2]) % (a[1] - a[2]) == 0:
			x = (b[1] - b[2]) / (a[1] - a[2])
			if (a[1] * b[2] - b[1] * a[2]) % (b[1] - b[2]) == 0:
				y = (a[1] * b[2] - b[1] * a[2]) / (b[1] - b[2])
				if (a[1] + y) * x == b[1] and (a[2] + y) * x == b[2] and (a[0] + y == b[0] or a[0] * x == b[0] or (a[0] + y) * x == b[0]):
					print(2)
					continue
	if a[0] - a[1] != 0:
		if (b[0] - b[1]) % (a[0] - a[1]) == 0:
			x = (b[0] - b[1]) / (a[0] - a[1])
			if (a[0] * b[1] - b[0] * a[1]) % (a[0] - a[1]) == 0:
				y = (a[0] * b[1] - b[0] * a[1]) / (a[0] - a[1])
				if a[0] * x + y == b[0] and a[1] * x + y == b[1] and (a[2] + y == b[2] or a[2] * x == b[2] or a[2] * x + y == b[2]):
					print(2)
					continue
	if a[0] - a[2] != 0:
		if (b[0] - b[2]) % (a[0] - a[2]) == 0:
			x = (b[0] - b[2]) / (a[0] - a[2])
			if (a[0] * b[2] - b[0] * a[2]) % (a[0] - a[2]) == 0:
				y = (a[0] * b[2] - b[0] * a[2]) / (a[0] - a[2])
				if a[0] * x + y == b[0] and a[2] * x + y == b[2] and (a[1] + y == b[1] or a[1] * x == b[1] or a[1] * x + y == b[1]):
					print(2)
					continue
	if a[1] - a[2] != 0:
		if (b[1] - b[2]) % (a[1] - a[2]) == 0:
			x = (b[1] - b[2]) / (a[1] - a[2])
			if (a[1] * b[2] - b[1] * a[2]) % (a[1] - a[2]) == 0:
				y = (a[1] * b[2] - b[1] * a[2]) / (a[1] - a[2])
				if a[2] * x + y == b[2] and a[1] * x + y == b[1] and (a[0] + y == b[0] or a[0] * x == b[0] or a[0] * x + y == b[0]):
					print(2)
					continue
	print(3)


from random import randint

def addition2test(a, b, p, q):
	k1 = p - a
	k2 = q - b
	if k1 == k2:
		return True
	return False

def addition3test(a, b, c, p, q, r):
	k1 = p - a
	k2 = q - b
	k3 = r - c
	if k1 == k2 and k2 == k3 and (k1 == k3):
		return True
	return False

def multi3test(a, b, c, p, q, r):
	if a == 0 or b == 0 or c == 0:
		return False
	v1 = p // a
	v2 = q // b
	v3 = r // c
	if v1 == v2 and v2 == v3 and (v1 == v3):
		if a * v1 == p and b * v2 == q and (c * v3 == r):
			return True
		else:
			return False
	return False

def mult2test(a, b, p, q):
	if a == 0 or b == 0:
		return False
	v1 = p // a
	v2 = q // b
	if v1 == v2:
		if a * v1 == p and b * v2 == q:
			return True
		else:
			return False
	return False

def addy2multall(a, b, c, p, q, r):
	if p == q:
		return False
	else:
		d = (a * q - p * b) / (p - q)
		if a + d == 0 and b + d != 0:
			k = q // (b + d)
		elif a + d != 0:
			k = p // (a + d)
		else:
			return False
		if p == k * (a + d) and q == k * (b + d) and (r == k * c):
			return True
	return False

def add2mul2(a, b, c, p, q, r):
	if r == 0:
		return False
	else:
		d = (p * c - a * r) // r
		if a + d == 0:
			return False
		else:
			k = p // (a + d)
			if k * (a + d) == p and b + d == q and (k * c == r):
				return True
	return False

def add3mul2(a, b, c, p, q, r):
	if p != q:
		d = (a * q - p * b) // (p - q)
		if a + d == 0 and b + d != 0:
			k = q // (b + d)
		elif a + d != 0:
			k = p // (a + d)
		else:
			return False
		if k * (a + d) == p and k * (b + d) == q and (c + d == r):
			return True
	return False

def add3mul3(a, b, c, p, q, r):
	if p != q:
		d = (a * q - p * b) // (p - q)
		if a + d == 0 and b + d != 0:
			k = q // (b + d)
		elif a + d != 0:
			k = p // (a + d)
		else:
			return False
		if k * (a + d) == p and k * (b + d) == q and (k * (c + d) == r):
			return True
	return False

def mul2addall(a, b, c, p, q, r):
	d = r - c
	if a != 0 or b != 0:
		if a != 0:
			k = (p - d) // a
		else:
			k = (p - d) // b
		if p == k * a + d and q == k * b + d and (r == c + d):
			return True
	else:
		return False
	return False

def mul2add2(a, b, c, p, q, r):
	d = r - c
	if a != 0:
		k = (p - d) // a
		if p == k * a + d and q == k * b and (r == c + d):
			return True
	return False

def mul3add2(a, b, c, p, q, r):
	if a != b:
		k = (p - q) // (a - b)
		d = p - k * a
		if p == k * a + d and q == k * b + d and (r == k * c):
			return True
	return False

def mul3add3(a, b, c, p, q, r):
	if a != b:
		k = (p - q) // (a - b)
		d = p - k * a
		if p == k * a + d and q == k * b + d and (r == k * c + d):
			return True
	return False

def add2add2(a, b, c, p, q, r):
	d2 = r - c
	d1 = p - a - d2
	if a + d1 + d2 == p and q == b + d1 and (r == c + d2):
		return True
	else:
		return False

def mul2mul2(a, b, c, p, q, r):
	if c == 0 or b == 0:
		return False
	else:
		k1 = r // c
		k2 = q // b
		if k1 * k2 * a == p and k2 * b == q and (k1 * c == r):
			return True
	return False
for _ in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	(p, q, r) = list(map(int, input().split()))
	if a == p and b == q and (c == r):
		print(0)
	elif a == p and b == q or (b == q and c == r) or (a == p and c == r):
		print(1)
	elif mult2test(a, b, p, q) and c == r or (mult2test(a, c, p, r) and b == q) or (mult2test(b, c, q, r) and a == p):
		print(1)
	elif multi3test(a, b, c, p, q, r):
		print(1)
	elif addition2test(a, b, p, q) and c == r or (addition2test(a, c, p, r) and b == q) or (addition2test(b, c, q, r) and a == p):
		print(1)
	elif addition3test(a, b, c, p, q, r):
		print(1)
	elif a == p or b == q or c == r:
		print(2)
	elif addition2test(a, b, p, q) or addition2test(b, c, q, r) or addition2test(a, c, p, r):
		print(2)
	elif mult2test(a, b, p, q) or mult2test(b, c, q, r) or mult2test(a, c, p, r):
		print(2)
	elif addy2multall(a, b, c, p, q, r) or addy2multall(b, c, a, q, r, p) or addy2multall(c, a, b, r, p, q):
		print(2)
	elif add2mul2(a, b, c, p, q, r) or add2mul2(b, a, c, q, p, r) or add2mul2(c, b, a, r, q, p) or add2mul2(b, c, a, q, r, p) or add2mul2(a, c, b, p, r, q) or add2mul2(c, a, b, r, p, q):
		print(2)
	elif add3mul3(a, b, c, p, q, r) or add3mul3(b, c, a, q, r, p) or add3mul3(c, a, b, r, p, q):
		print(2)
	elif add3mul2(a, b, c, p, q, r) or add3mul2(b, c, a, q, r, p) or add3mul2(c, a, b, r, p, q):
		print(2)
	elif add2add2(a, b, c, p, q, r) or add2add2(b, a, c, q, p, r) or add2add2(c, b, a, r, q, p) or add2add2(b, c, a, q, r, p) or add2add2(a, c, b, p, r, q) or add2add2(c, a, b, r, p, q):
		print(2)
	elif mul2addall(a, b, c, p, q, r) or mul2addall(b, c, a, q, r, p) or mul2addall(c, a, b, r, p, q):
		print(2)
	elif mul2add2(a, b, c, p, q, r) or mul2add2(b, a, c, q, p, r) or mul2add2(c, b, a, r, q, p) or mul2add2(b, c, a, q, r, p) or mul2add2(a, c, b, p, r, q) or mul2add2(c, a, b, r, p, q):
		print(2)
	elif mul3add3(a, b, c, p, q, r) or mul3add3(b, c, a, q, r, p) or mul3add3(c, a, b, r, p, q):
		print(2)
	elif mul3add2(a, b, c, p, q, r) or mul3add2(b, c, a, q, r, p) or mul3add2(c, a, b, r, p, q):
		print(2)
	elif mul2mul2(a, b, c, p, q, r) or mul2mul2(b, a, c, q, p, r) or mul2mul2(c, b, a, r, q, p) or mul2mul2(b, c, a, q, r, p) or mul2mul2(a, c, b, p, r, q) or mul2mul2(c, a, b, r, p, q):
		print(2)
	else:
		print(3)


def n_solved(p, q, r, a, b, c):
	s = 0
	if p == a:
		s += 1
	if q == b:
		s += 1
	if r == c:
		s += 1
	return s

def can_solve_in_one_move_2(p, q, a, b):
	if a - p == b - q:
		return True
	if p != 0 and a % p == 0 and (a // p * q == b):
		return True
	return False

def can_solve_in_one_move_3(p, q, r, a, b, c):
	if a - p == b - q and a - p == c - r:
		return True
	if p != 0 and a % p == 0 and (a // p * q == b) and (a // p * r == c):
		return True
	return False

def fix_one_fixes_other(p, a, q, r, b, c):
	n = a - p
	if can_solve_in_one_move_2(q + n, r, b, c) or can_solve_in_one_move_2(q, r + n, b, c) or can_solve_in_one_move_2(q + n, r + n, b, c):
		return True
	if p != 0 and a % p == 0:
		n = a // p
		if can_solve_in_one_move_2(q * n, r, b, c) or can_solve_in_one_move_2(q, r * n, b, c) or can_solve_in_one_move_2(q * n, r * n, b, c):
			return True
	return False

def can_align_others(p, a, q, r, b, c):
	if q != 0:
		x = (b + p - a) / q
		if x.is_integer():
			if can_solve_in_one_move_3(p, q * x, r * x, a, b, c):
				return True
	if a != 0:
		x = b * p / a - 9
		if x.is_integer():
			if can_solve_in_one_move_3(p, q + x, r + x, a, b, c):
				return True
	return False

def can_solve_in_two_move_3(p, q, r, a, b, c):
	if a - b != 0:
		x = (p * b - a * q) / (a - b)
		if x.is_integer():
			if can_solve_in_one_move_3(p + x, q + x, r + x, a, b, c):
				return True
	if q - r != 0:
		x = (b - c) / (q - r)
		if x.is_integer():
			if can_solve_in_one_move_3(p * x, q * x, r * x, a, b, c):
				return True

def _sol(p, q, r, a, b, c):
	ns = n_solved(p, q, r, a, b, c)
	if ns == 3:
		return 0
	if ns == 2:
		return 1
	if ns == 1:
		if can_solve_in_one_move_2(p, q, a, b) or can_solve_in_one_move_2(p, r, a, c) or can_solve_in_one_move_2(q, r, b, c):
			return 1
		return 2
	if ns == 0:
		if can_solve_in_one_move_3(p, q, r, a, b, c):
			return 1
		if can_solve_in_one_move_2(p, q, a, b) or can_solve_in_one_move_2(p, r, a, c) or can_solve_in_one_move_2(q, r, b, c):
			return 2
		if fix_one_fixes_other(p, a, q, r, b, c) or fix_one_fixes_other(q, b, p, r, a, c) or fix_one_fixes_other(r, c, p, q, a, b):
			return 2
		if can_align_others(p, a, q, r, b, c) or can_align_others(q, b, p, r, a, c) or can_align_others(r, c, p, q, a, b):
			return 2
		if can_solve_in_two_move_3(p, q, r, a, b, c):
			return 2
		return 3

def sol() -> int:
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	return _sol(p, q, r, a, b, c)
N = int(input())
for i in range(N):
	s = sol()
	print(s)


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


intput = lambda : [int(i) for i in input().split()]
from sys import stdout
sol = '3332323313233322223333'
subsets = ['100', '010', '001', '110', '101', '011', '111']
eq = lambda x, y: abs(x - y) < 1e-06

def check(x):
	if x == [9, 7, 4]:
		print('Debug')
	if x == y:
		return 0
	(d, q, f) = ([], [], [])
	for i in range(3):
		d.append(y[i] - x[i])
		q.append(0.5 if x[i] == 0 else y[i] / x[i])
		f.append(q[i] % 1 == 0)
	for i in range(3):
		(j, k) = ((i + 1) % 3, (i + 2) % 3)
		if x[j] == y[j] and x[k] == y[k]:
			return 1
		if x[i] == y[i] and (d[j] == d[k] or (f[j] and eq(q[j], q[k]))):
			return 1
	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])):
		return 1
	return 2

def move(subset, oper, d):
	res = x.copy()
	for i in range(3):
		if subset[i] == '1':
			res[i] = res[i] + d if oper else res[i] * d
	return res
for tc in range(int(input())):
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	a = check(x)
	if a < 2:
		print(a)
		continue
	(d, q, f) = ([], [], [])
	for i in range(3):
		d.append(y[i] - x[i])
		q.append(0.5 if x[i] == 0 else y[i] / x[i])
		f.append(q[i] % 1 == 0)
	flag = False
	for subset in subsets:
		for i in range(3):
			a = check(move(subset, True, d[i]))
			if a < 2:
				print(2)
				flag = True
				break
			if f[i]:
				a = check(move(subset, False, q[i]))
				if a < 2:
					print(2)
					flag = True
					break
		if flag:
			break
	if flag:
		continue
	for i in range(3):
		(j, k) = ((i + 1) % 3, (i + 2) % 3)
		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):
			print(2)
			flag = True
			break
	if flag:
		continue
	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])):
		print(2)
		continue
	print(3)


def function1(p, q, r, a, b, c):
	listA = []
	listM = []
	if p != a:
		listA.append(a - p)
		if p and a % p == 0:
			listM.append(a // p)
		else:
			listM.append(None)
	if q != b:
		listA.append(b - q)
		if q and b % q == 0:
			listM.append(b // q)
		else:
			listM.append(None)
	if r != c:
		listA.append(c - r)
		if r and c % r == 0:
			listM.append(c // r)
		else:
			listM.append(None)
	if len(listA) == 0:
		return 0
	elif len(listA) == 1:
		return 1
	elif len(listA) == 2:
		if listA[0] == listA[1] or (listM[0] != None and listM[1] != None and (listM[0] == listM[1])):
			return 1
		else:
			return 2
	elif len(listA) == 3:
		flag = 0
		if listA[0] == listA[1] == listA[2] or (listM[0] != None and listM[1] != None and (listM[2] != None) and (listM[0] == listM[1] == listM[2])):
			return 1
			flag = -1
		elif listA[0] == listA[1] or listA[1] == listA[2] or listA[0] == listA[2] or (listA[0] == listA[1] + listA[2]) or (listA[1] == listA[0] + listA[2]) or (listA[2] == listA[0] + listA[1]):
			return 2
			flag = -1
		elif listM[0] != None and listM[1] != None and (listM[2] != None) and (listM[0] == listM[1] * listM[2] or listM[1] == listM[0] * listM[2] or listM[2] == listM[0] * listM[1]):
			return 2
			flag = -1
		elif listM[0] != None and listM[1] != None and (listM[0] == listM[1]) or (listM[1] != None and listM[2] != None and (listM[1] == listM[2])) or (listM[0] != None and listM[2] != None and (listM[0] == listM[2])):
			return 2
			flag = -1
		elif listM[0] != None and (b == q * listM[0] + listA[2] or c == r * listM[0] + listA[1] or b == (q + listA[2]) * listM[0] or (c == (r + listA[1]) * listM[0])):
			return 2
			flag = -1
		elif listM[1] != None and (a == p * listM[1] + listA[2] or c == r * listM[1] + listA[0] or a == (p + listA[2]) * listM[1] or (c == (r + listA[0]) * listM[1])):
			return 2
			flag = -1
		elif listM[0] != None and (b == q * listM[0] + listA[2] or c == r * listM[0] + listA[1] or b == (q + listA[2]) * listM[0] or (c == (r + listA[1]) * listM[0])):
			return 2
			flag = -1
		elif listM[2] != None and (a == p * listM[2] + listA[1] or b == q * listM[2] + listA[0] or a == (p + listA[1]) * listM[2] or (b == (q + listA[0]) * listM[2])):
			return 2
			flag = -1
		elif p - q and (a - b) % (p - q) == 0 and ((p * b - q * a) % (p - q) == 0) and (c == r * ((a - b) // (p - q)) + (p * b - q * a) // (p - q) or c == r * ((a - b) // (p - q)) or c == r + (p * b - q * a) // (p - q)):
			return 2
			flag = -1
		elif p - q and a - b and ((a - b) % (p - q) == 0) and ((b * p - a * q) % (a - b) == 0) and (c == (r + (b * p - a * q) // (a - b)) * ((a - b) // (p - q)) or c == r * ((a - b) // (p - q)) or c == r + (b * p - a * q) // (a - b)):
			return 2
			flag = -1
		(a, b, c) = (b, c, a)
		(p, q, r) = (q, r, p)
		if not flag and p - q and ((a - b) % (p - q) == 0) and ((p * b - q * a) % (p - q) == 0) and (c == r * ((a - b) // (p - q)) + (p * b - q * a) // (p - q) or c == r * ((a - b) // (p - q)) or c == r + (p * b - q * a) // (p - q)):
			return 2
			flag = -1
		elif not flag and p - q and a - b and ((a - b) % (p - q) == 0) and ((b * p - a * q) % (a - b) == 0) and (c == (r + (b * p - a * q) // (a - b)) * ((a - b) // (p - q)) or c == r * ((a - b) // (p - q)) or c == r + (b * p - a * q) // (a - b)):
			return 2
			flag = -1
		(a, b, c) = (b, c, a)
		(p, q, r) = (q, r, p)
		if not flag and p - q and ((a - b) % (p - q) == 0) and ((p * b - q * a) % (p - q) == 0) and (c == r * ((a - b) // (p - q)) + (p * b - q * a) // (p - q) or c == r * ((a - b) // (p - q)) or c == r + (p * b - q * a) // (p - q)):
			return 2
			flag = -1
		elif not flag and p - q and a - b and ((a - b) % (p - q) == 0) and ((b * p - a * q) % (a - b) == 0) and (c == (r + (b * p - a * q) // (a - b)) * ((a - b) // (p - q)) or c == r * ((a - b) // (p - q)) or c == r + (b * p - a * q) // (a - b)):
			return 2
			flag = -1
		if flag == 0:
			return 3
l1 = int(input())
for _ in range(l1):
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	temp1 = function1(p, q, r, a, b, c)
	print(temp1)


def aa22(p, q, r, a, b, c):
	if q + a - p + c - r == b:
		return 1
	else:
		return 0

def aa21(p, q, r, a, b, c):
	if p - q == a - b:
		return 1
	else:
		return 0

def as22(p, q, r, a, b, c):
	if p + b - c + r - q == a:
		return 1
	else:
		return 0

def am22(p, q, r, a, b, c):
	if r != 0 and c != 0 and (c % r == 0) and (b * r % c == 0) and (b * r // c - q == a - p):
		return 1
	else:
		return 0

def am21(p, q, r, a, b, c):
	if r != 0 and c % r == 0 and (p - q == a - b):
		return 1
	else:
		return 0

def am23(p, q, r, a, b, c):
	if r != 0 and c != 0 and (c % r == 0) and (b * r % c == 0) and (a * r % c == 0) and (a * r // c - p == b * r // c - q):
		return 1
	else:
		return 0

def am32(p, q, r, a, b, c):
	if q + c - r != 0 and p + c - r != 0 and (b // (q + c - r) == a // (p + c - r)) and (b % (q + c - r) == 0) and (a % (p + c - r) == 0):
		return 1
	else:
		return 0

def ma33(p, q, r, a, b, c):
	if p - q != 0 and (b * p - a * q) % (p - q) == 0 and (q - r != 0) and (p != 0) and ((c * q - b * r) % (q - r) == 0) and ((b * p - a * q) // (p - q) == (c * q - b * r) // (q - r)) and ((a - (b * p - a * q) // (p - q)) % p == 0):
		return 1
	else:
		return 0

def am33(p, q, r, a, b, c):
	if a - b != 0 and (b * p - a * q) % (a - b) == 0 and (b - c != 0) and ((c * q - b * r) % (b - c) == 0) and ((b * p - a * q) // (a - b) == (c * q - b * r) // (b - c)) and (p + (b * p - a * q) // (a - b) != 0) and (a % (p + (b * p - a * q) // (a - b)) == 0):
		return 1
	else:
		return 0

def ma22(p, q, r, a, b, c):
	if p != 0 and q != 0 and (a % p == 0) and ((b - c + r) % q == 0) and (a // p == (b - c + r) // q):
		return 1
	else:
		return 0

def ma21(p, q, r, a, b, c):
	if p != 0 and q != 0 and (a % p == 0) and (b % q == 0) and (a // p == b // q):
		return 1
	else:
		return 0

def ma23(p, q, r, a, b, c):
	if q != 0 and p != 0 and ((b - c + r) % q == 0) and ((a - c + r) % p == 0) and ((b - c + r) // q == (a - c + r) // p):
		return 1
	else:
		return 0

def ma32(p, q, r, a, b, c):
	if r != 0 and q * c % r == 0 and (p * c % r == 0) and (b - q * c // r == a - p * c // r) and (c % r == 0):
		return 1
	else:
		return 0

def ms22(p, q, r, a, b, c):
	if q != 0 and p != 0 and ((b + r - c) % q == 0) and (a % p == 0) and ((b + r - c) // q == a // p):
		return 1
	else:
		return 0

def mm22(p, q, r, a, b, c):
	if q * c != 0 and b * r % (q * c) == 0 and (p != 0) and (a % p == 0) and (a // p == b * r // (q * c)):
		return 1
	else:
		return 0

def mm21(p, q, r, a, b, c):
	if r != 0 and c % r == 0 and (q != 0) and (p != 0) and (b // q == a // p) and (b % q == 0) and (a % p == 0):
		return 1
	else:
		return 0

def sa22(p, q, r, a, b, c):
	if q - b + c - r == p - a:
		return 1
	else:
		return 0

def sa21(p, q, r, a, b, c):
	if p - a == q - b:
		return 1
	else:
		return 0

def sm32(p, q, r, a, b, c):
	if q - r + c != 0 and p - r + c != 0 and (b // (q - r + c) == a // (p - r + c)) and (b % (q - r + c) == 0) and (a % (p - r + c) == 0):
		return 1
	else:
		return 0

def as2(q, r, b, c):
	if q - r == b - c:
		return 1
	else:
		return 0

def m2(q, r, b, c):
	if r != 0 and q != 0 and (b // q == c // r) and (b % q == 0) and (c % r == 0):
		return 1
	else:
		return 0

def as3(p, q, r, a, b, c):
	if p - q == a - b and q - r == b - c and (p - r == a - c):
		return 1
	else:
		return 0

def m3(p, q, r, a, b, c):
	if q != 0 and r != 0 and (p != 0) and (a // p == b // q) and (b // q == c // r) and (a % p == 0) and (b % q == 0) and (c % r == 0):
		return 1
	else:
		return 0
t = int(input())
while t > 0:
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	l = []
	d = []
	l3 = []
	l.append(p)
	l.append(q)
	l.append(r)
	l.append(p)
	l.append(r)
	l.append(q)
	l.append(q)
	l.append(p)
	l.append(r)
	l.append(q)
	l.append(r)
	l.append(p)
	l.append(r)
	l.append(p)
	l.append(q)
	l.append(r)
	l.append(q)
	l.append(p)
	l3.append(a)
	l3.append(b)
	l3.append(c)
	l3.append(a)
	l3.append(c)
	l3.append(b)
	l3.append(b)
	l3.append(a)
	l3.append(c)
	l3.append(b)
	l3.append(c)
	l3.append(a)
	l3.append(c)
	l3.append(a)
	l3.append(b)
	l3.append(c)
	l3.append(b)
	l3.append(a)
	l2 = []
	l4 = []
	if p == a:
		l2.append(q)
		l2.append(r)
		l4.append(b)
		l4.append(c)
	if q == b:
		l2.append(p)
		l2.append(r)
		l4.append(a)
		l4.append(c)
	if r == c:
		l2.append(p)
		l2.append(q)
		l4.append(a)
		l4.append(b)
	sol = 0
	ans = 0
	cnt = (p == a) + (q == b) + (r == c)
	if p == a and q == b and (r == c):
		ans = 4
	elif cnt == 2:
		ans = 1
	elif cnt == 1:
		for i in range(0, 2, 2):
			sol = as2(l2[i], l2[i + 1], l4[i], l4[i + 1])
			if sol == 1:
				break
			sol = m2(l2[i], l2[i + 1], l4[i], l4[i + 1])
			if sol == 1:
				break
		if sol == 1:
			ans = 1
			sol = 0
		else:
			ans = 2
	elif cnt == 0 and ans == 0:
		sol = as3(p, q, r, a, b, c)
		if sol == 1:
			ans = 1
		sol = m3(p, q, r, a, b, c)
		if sol == 1:
			ans = 1
	sol = 0
	for i in range(0, 16, 3):
		if ans != 0:
			break
		sol = aa22(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = aa21(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = as22(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = am22(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = am21(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = am23(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = am32(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = ma33(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = am33(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = ma22(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = ma21(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = ma23(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = ma32(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = ms22(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = mm22(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = mm21(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = sa22(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
		sol = sm32(l[i], l[i + 1], l[i + 2], l3[i], l3[i + 1], l3[i + 2])
		if sol == 1:
			break
	if sol == 1 and ans == 0:
		ans = 2
	elif ans == 0 and sol != 1:
		ans = 3
	if ans == 4:
		print('0')
	else:
		print(ans)
	t = t - 1


def ch1(a, b):
	if b / a == int(b / a):
		return True
	return False

def ch3(a, b):
	if abs(a) <= abs(b) and a != 0:
		return True
	return False

def ch2(a, b, c, d):
	if ch3(a, b) and ch1(a, b) and ch3(c, d) and ch1(c, d):
		if b / a == d / c:
			return True
	return False

def ch4(a, b, c, d, e, f):
	if ch3(a, b) and ch1(a, b) and ch3(c, d) and ch1(c, d) and ch3(e, f) and ch1(e, f):
		if b / a * (d / c) == f / e:
			return True
	return False

def ch5(a, b, c, d, e, f):
	if ch3(a, b) and ch1(a, b) and ch3(c, d) and ch1(c, d) and ch3(e, f) and ch1(e, f):
		if b / a == d / c == f / e:
			return True
	return False

def ch6(a, b, x, c, y, z):
	if ch3(a, b) and ch1(a, b):
		if x / (b / a) - c == z - y:
			return True
	return False

def ch7(a, b, c, d, e, f):
	if ch3(a, b) and ch1(a, b):
		temp1 = b / a
		if ch3(temp1, d) and ch1(temp1, d):
			temp2 = d / temp1
			temp3 = temp2 - c
			if f - e == temp3:
				return True
		if ch3(temp1, f) and ch1(temp1, f):
			temp2 = f / temp1
			temp3 = temp2 - e
			if d - c == temp3:
				return True
	return False

def ch8(a, b, c, d, e, f):
	if ch3(a, b) and ch1(a, b):
		temp1 = b / a
		temp2 = e * temp1
		temp3 = f - temp2
		if temp3 == d - c:
			return True
	return False

def ch9(st, li):
	for i in range(st, 3):
		li[i] = 0
		fl.append(li[:])
		ch9(i + 1, li)
		li[i] = li2[i]
t = int(input())
for _ in range(t):
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	(x, y, z) = (a - p, b - q, c - r)
	ct = 0
	if a == 0:
		ct += 1
	if b == 0:
		ct += 1
	if c == 0:
		ct += 1
	l = [3]
	flag = [0 for x in range(26)]
	if x == y == z == 0:
		l.append(0)
	elif ct == 3 or (ct == 2 and (x == 0 and p != 0 or (y == 0 and q != 0) or (z == 0 and r != 0))) or (x == y == 0 or x == z == 0 or y == z == 0) or (x == y == z):
		l.append(1)
	elif abs(a) == abs(p) and abs(b) == abs(q) and (abs(c) == abs(r)):
		l.append(1)
	elif x == 0 and y == z or (y == 0 and x == z) or (z == 0 and y == x):
		l.append(1)
	elif x == 0 and ch2(q, b, r, c) or (y == 0 and ch2(p, a, r, c)) or (z == 0 and ch2(p, a, q, b)):
		l.append(1)
	elif ch5(p, a, q, b, r, c):
		l.append(1)
	elif a == b == c:
		l.append(2)
	elif ch5(abs(p), abs(a), abs(q), abs(b), abs(r), abs(c)):
		l.append(2)
	elif x == 0 or y == 0 or z == 0:
		l.append(2)
	elif x + y == z or x + z == y or y + z == x:
		l.append(2)
	elif ch4(p, a, q, b, r, c) or ch4(q, b, r, c, p, a) or ch4(p, a, r, c, q, b):
		l.append(2)
	elif ct == 2:
		l.append(2)
	elif x == b == c or y == a == c or z == a == b:
		l.append(2)
	elif x == y or y == z or x == z:
		l.append(2)
	elif ch2(p, a, q, b) or ch2(q, b, r, c) or ch2(p, a, r, c):
		l.append(2)
	elif ch3(q, b) and ch1(q, b) and (z == a - b / q * p or x == c - b / q * r):
		l.append(2)
	elif ch3(p, a) and ch1(p, a) and (y == c - a / p * r or z == b - a / p * q):
		l.append(2)
	elif ch3(r, c) and ch1(r, c) and (x == b - c / r * q or y == a - c / r * p):
		l.append(2)
	elif ch5(p - q, a - b, q - r, b - c, p - r, a - c):
		l.append(2)
	elif ch2(p - q, a - b, r, c) or ch2(q - r, b - c, p, a) or ch2(p - r, a - c, q, b):
		l.append(2)
	elif ch6(p - q, a - b, a, p, r, c) or ch6(p - r, a - c, a, p, q, b) or ch6(q - r, b - c, b, q, p, a):
		l.append(2)
	elif ch7(p, a, q, b, r, c) or ch7(q, b, r, c, p, a) or ch7(r, c, p, a, q, b):
		l.append(2)
	elif ch8(p - q, a - b, r, c, p, a) or ch8(p - r, a - c, q, b, p, a) or ch8(q - r, b - c, p, a, q, b):
		l.append(2)
	elif a == 0 and b == c or (b == 0 and a == c) or (c == 0 and a == b):
		l.append(2)
	elif abs(a) - abs(p) == abs(b) - abs(q) == abs(c) - abs(r):
		ans = abs(a) - abs(p)
		tp = p + ans
		tq = q + ans
		tr = r + ans
		for _ in range(2):
			tp *= -1
			for _ in range(2):
				tq *= -1
				for _ in range(2):
					tr *= -1
					if tp == a and tq == b and (tr == c):
						l.append(2)
		tp = p - ans
		tq = q - ans
		tr = r - ans
		for _ in range(2):
			tp *= -1
			for _ in range(2):
				tq *= -1
				for _ in range(2):
					tr *= -1
					if tp == a and tq == b and (tr == c):
						l.append(2)
	tp = p
	tq = q
	tr = r
	for _ in range(2):
		tp *= -1
		for _ in range(2):
			tq *= -1
			for _ in range(2):
				tr *= -1
				if a - tp == b - tq == c - tr:
					l.append(2)
	li = [p, q, r]
	li2 = [p, q, r]
	fl = []
	ch9(0, li)
	for i in fl:
		x = a - i[0]
		y = b - i[1]
		z = c - i[2]
		if x == y and z == 0 or (x == z and y == 0) or (y == z and x == 0):
			l.append(2)
	print(min(l))


from sys import stdin

def check(x, y, X, Y):
	if X - x == Y - y:
		return True
	if x != 0 and y != 0 and (X % x == 0) and (Y % y == 0) and (X // x == Y // y):
		return True
	return False

def case2():
	if p == a and check(q, r, b, c) or (q == b and check(p, r, a, c)) or (r == c and check(p, q, a, b)):
		return 1
	return 2

def case3():
	if a - p == b - q and b - q == c - r:
		return 1
	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 (b // q == c // r):
		return 1
	if p - q != 0 and q - r != 0 and (r - p != 0) and ((a - b) % (p - q) == 0) and ((b - c) % (q - r) == 0) and ((c - a) % (r - p) == 0) and ((a - b) // (p - q) == (b - c) // (q - r)) and ((c - a) // (r - p) == (a - b) // (p - q)):
		return 2
	if check(p, q, a, b) or check(q, r, b, c) or check(r, p, c, a):
		return 2
	if check(q + (a - p), r + (a - p), b, c) or check(p + (b - q), r + (b - q), a, c) or check(p + (c - r), q + (c - r), a, b):
		return 2
	if check(q, r, b - (a - p), c - (a - p)) or check(p, r, a - (b - q), c - (b - q)) or check(p, q, a - (c - r), b - (c - r)):
		return 2
	if p != 0 and a % p == 0 and check(q * (a // p), r * (a // p), b, c) or (q != 0 and b % q == 0 and check(p * (b // q), r * (b // q), a, c)) or (r != 0 and c % r == 0 and check(p * (c // r), q * (c // r), a, b)):
		return 2
	if p != 0 and a != 0 and (a % p == 0) and (b % (a // p) == 0) and (c % (a // p) == 0) and check(q, r, b // (a // p), c // (a // p)) or (q != 0 and b != 0 and (b % q == 0) and (a % (b // q) == 0) and (c % (b // q) == 0) and check(p, r, a // (b // q), c // (b // q))) or (r != 0 and c != 0 and (c % r == 0) and (a % (c // r) == 0) and (b % (c // r) == 0) and check(p, q, a // (c // r), b // (c // r))):
		return 2
	if check(q + (a - p), r, b, c) or check(q, r + (a - p), b, c) or check(p + (b - q), r, a, c) or check(p, r + (b - q), a, c) or check(p + (c - r), q, a, b) or check(p, r + (c - r), a, c):
		return 2
	if check(q, r, b - (a - p), c) or check(q, r, b, c - (a - p)) or check(p, r, a - (b - q), c) or check(p, r, a, c - (b - q)) or check(p, q, a - (c - r), b) or check(p, q, a, b - (c - r)):
		return 2
	if p != 0 and a % p == 0 and (check(q * (a // p), r, b, c) or check(q, r * (a // p), b, c)) or (q != 0 and b % q == 0 and (check(p * (b // q), r, a, c) or check(p, r * (b // q), a, c))) or (r != 0 and c % r == 0 and (check(p, q * (c // r), a, b) or check(p * (c // r), q, a, b))):
		return 2
	if p != 0 and a != 0 and (a % p == 0) and (b % (a // p) == 0 and check(q, r, b // (a // p), c) or (c % (a // p) == 0 and check(q, r, b, c // (a // p)))):
		return 2
	if q != 0 and b != 0 and (b % q == 0) and (a % (b // q) == 0 and check(p, r, a // (b // q), c) or (c % (b // q) == 0 and check(p, r, a, c // (b // q)))):
		return 2
	if r != 0 and c != 0 and (c % r == 0) and (a % (c // r) == 0 and check(p, q, a // (c // r), b) or (b % (c // r) == 0 and check(p, q, a, b // (c // r)))):
		return 2
	return 3

def main():
	arr = []
	if p != a:
		arr.append(0)
	if q != b:
		arr.append(1)
	if r != c:
		arr.append(2)
	if len(arr) == 0:
		return 0
	if len(arr) == 1:
		return 1
	if len(arr) == 2:
		return case2()
	return case3()
for _ in range(int(stdin.readline())):
	(p, q, r) = map(int, stdin.readline().split())
	(a, b, c) = map(int, stdin.readline().split())
	print(main())


t = int(input())

def check1(t1, t2):
	(x1, y1, z1) = t1
	(x2, y2, z2) = t2
	arr1 = [x2 - x1, y2 - y1, z2 - z1]
	arr2 = []
	if x1 != 0 and x2 / x1 == x2 // x1:
		arr2.append(x2 // x1)
	if y1 != 0 and y2 / y1 == y2 // y1:
		arr2.append(y2 // y1)
	if z1 != 0 and z2 / z1 == z2 // z1:
		arr2.append(z2 // z1)
	if x1 == 0 and x2 == 0:
		arr2.append(1)
	if y1 == 0 and y2 == 0:
		arr2.append(1)
	if z1 == 0 and z2 == 0:
		arr2.append(1)
	while 0 in arr1:
		arr1.remove(0)
	if len(arr1) == 1:
		return True
	if len(arr1) == 2:
		if arr1[0] == arr1[1]:
			return True
	elif arr1[0] == arr1[1] and arr1[1] == arr1[2]:
		return True
	if len(arr2) == 3:
		while 1 in arr2:
			arr2.remove(1)
		if len(arr2) == 1:
			return True
		if len(arr2) == 2:
			if arr2[0] == arr2[1]:
				return True
		elif arr2[0] == arr2[1] and arr2[1] == arr2[2]:
			return True
	return False
for _ in range(t):
	l1 = [int(i) for i in input().split()]
	l2 = [int(i) for i in input().split()]
	if l1 == l2:
		print(0)
		continue
	else:
		if check1(l1, l2):
			print(1)
			continue
		else:
			(a, b) = ([], [])
			for i in range(3):
				a.append(l2[i] - l1[i])
				if l1[i] != 0 and l2[i] / l1[i] == l2[i] // l1[i]:
					b.append(l2[i] // l1[i])
				if l1[i] == 0 and l2[i] == 0:
					b.append(1)
			if 0 in a or 1 in b:
				print(2)
				continue
			elif len(set(a)) == 2 or len(b) - len(set(b)) == 1:
				print(2)
				continue
			else:
				if a[0] + a[1] == a[2] or a[0] + a[2] == a[1] or a[1] + a[2] == a[0]:
					print(2)
					continue
				if len(b) == 3:
					if b[0] * b[1] == b[2] or b[0] * b[2] == b[1] or b[1] * b[2] == b[0]:
						print(2)
						continue
				bol = False
				for i in range(3):
					diff = a[i]
					(p, q, r) = ([l2[0] - diff, l2[1] - diff, l2[2] - diff], [l2[0] - diff, l2[1] - diff, l2[2] - diff], [l2[0] - diff, l2[1] - diff, l2[2] - diff])
					for j in range(3):
						if i != j:
							p[j] = p[j] + diff
							break
					for k in range(3):
						if i != k and j != k:
							q[k] = q[k] + diff
							break
					if check1(l1, p) or check1(l1, q) or check1(l1, r):
						print(2)
						bol = True
						break
				if bol:
					continue
				bol = False
				for i in range(3):
					if l1[i] != 0:
						pro = l2[i] / l1[i]
						if pro == int(pro):
							p = [l1[0] * pro, l1[1] * pro, l1[2] * pro]
							if check1(p, l2):
								print(2)
								bol = True
								break
				if bol:
					continue
				if len(set(l1)) == 3:
					l3 = [(l2[0] - l2[1]) / (l1[0] - l1[1]), (l2[1] - l2[2]) / (l1[1] - l1[2]), (l2[2] - l2[0]) / (l1[2] - l1[0])]
					if l3[0] == l3[1] and l3[1] == l3[2] and (l3[0] == int(l3[0])):
						print(2)
						continue
				bol = False
				for i in range(3):
					diff = -1 * a[i]
					(p, q, r) = ([l1[0] - diff, l1[1] - diff, l1[2] - diff], [l1[0] - diff, l1[1] - diff, l1[2] - diff], [l1[0] - diff, l1[1] - diff, l1[2] - diff])
					for j in range(3):
						if i != j:
							p[j] = p[j] + diff
							break
					for k in range(3):
						if i != k and j != k:
							q[k] = q[k] + diff
							break
					if check1(p, l2) or check1(q, l2) or check1(r, l2):
						bol = True
						print(2)
						break
				if bol:
					continue
				bol = False
				for i in range(3):
					if l1[i] != 0 and l2[i] != 0:
						pro = l2[i] / l1[i]
						if pro == int(pro):
							(p, q, r) = (l2[0] / pro, l2[1] / pro, l2[2] / pro)
							if p == int(p) and q == int(q) and (r == int(r)):
								lp = [int(p), int(q), int(r)]
								if check1(l1, lp):
									bol = True
									print(2)
									break
				if bol:
					continue
		print(3)


from sys import stdin
from itertools import combinations, permutations
import functools

def Chef(w):
	if ord(w) != ord('w'):
		return True
	return False

def Coin(p, a, q, b, r, c):
	x = b - a
	d = q - p
	if d != 0:
		y = a - 1 * p * (x / d)
		if 1 * r * (x / d) + y == c:
			if x % d == 0:
				return True
		if x % d == 0 and r + y == c:
			return True
		if x % d == 0 and r * x == c:
			return True
	return False

def Code():
	return True

def check(p, a, q, b):
	if p == a or q == b:
		return True
	if a - p == b - q:
		return True
	if p != 0 and q != 0 and (a % p == 0) and (b % q == 0) and (a / p == b / q):
		return True
	return False

def CodeStabiliy():
	return False
t = int(input())
for _ in range(t):
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	Chef('p')
	if p == a and q == b and (r == c):
		print(0)
		continue
	if p == a and check(q, b, r, c) or (q == b and check(p, a, r, c)) or (r == c and check(q, b, p, a)):
		print(1)
		continue
	diff = a - p
	if q + diff == b and r + diff == c:
		print(1)
		continue
	if p != 0 and a % p == 0:
		diff = a / p
		if q * diff == b and r * diff == c:
			print(1)
			continue
	d = 0
	if p != 0 and a % p == 0:
		d = a / p
		if check(q * d, b, r * d, c) or check(q * d, b, r, c) or check(q, b, r * d, c) or check(q, b, r, c):
			print(2)
			continue
	d = a - p
	if check(q + d, b, r + d, c) or check(q + d, b, r, c) or check(q, b, r + d, c) or check(q, b, r, c):
		print(2)
		continue
	if q != 0 and b % q == 0:
		d = b / q
		if check(p * d, a, r * d, c) or check(p * d, a, r, c) or check(p, a, r * d, c) or check(p, a, r, c):
			print(2)
			continue
	d = b - q
	if check(p + d, a, r + d, c) or check(p + d, a, r, c) or check(p, a, r + d, c) or check(p, a, r, c):
		print(2)
		continue
	if r != 0 and c % r == 0:
		d = c / r
		if check(q * d, b, p * d, a) or check(q * d, b, p, a) or check(q, b, p * d, a) or check(q, b, p, a):
			print(2)
			continue
	d = c - r
	if check(q + d, b, p + d, a) or check(q + d, b, p, a) or check(q, b, p + d, a) or check(q, b, p, a):
		print(2)
		continue
	if Coin(p, a, q, b, r, c) or Coin(p, a, r, c, q, b) or Coin(q, b, r, c, p, a):
		print(2)
		continue
	Code()
	print(3)


def gunc(a, d, b, e, c, f, d1, d2, d3):
	zero = set()
	if d1 != 0:
		zero.add(d)
	if d2 != 0:
		zero.add(e)
	if d3 != 0:
		zero.add(f)
	zero = list(zero)
	if len(zero) == 1 and zero[0] == 0:
		return 1
	uni = set()
	if d1 != 0 and a != 0 and (d % a == 0):
		uni.add(d // a)
	if d2 != 0 and b != 0 and (e % b == 0):
		uni.add(e // b)
	if d3 != 0 and c != 0 and (f % c == 0):
		uni.add(f // c)
	uni = list(uni)
	if len(uni) == 1:
		x = uni[0]
		if d1 != 0 and d2 != 0 and (d3 != 0) and (a * x == d) and (b * x == e) and (c * x == f) or (d1 == 0 and d2 != 0 and (d3 != 0) and (b * x == e) and (c * x == f)) or (d2 == 0 and d3 != 0 and (d1 != 0) and (a * x == d) and (c * x == f)) or (d3 == 0 and d1 != 0 and (d2 != 0) and (a * x == d) and (b * x == e)):
			return 1
	return -1

def func1(d1, d2, d3):
	if d1 == d2 or d2 == d3 or d3 == d1 or (d1 + d2 == d3) or (d2 + d3 == d1) or (d3 + d1 == d2) or (d1 == 0) or (d2 == 0) or (d3 == 0):
		return 2
	return -1

def func232(a, d, b, e, c, f):
	x = b * d - a * e
	if e - d != 0 and x % (e - d) == 0:
		x = x // (e - d)
		if a + x != 0 and d % (a + x) == 0:
			y = d // (a + x)
			if (a + x) * y == d and (b + x) * y == e and (c + x == f):
				return 2
	return -1

def func233(a, d, b, e, c, f):
	x = b * d - a * e
	if e - d != 0 and x % (e - d) == 0:
		x = x // (e - d)
		if a + x != 0 and d % (a + x) == 0:
			y = d // (a + x)
			if (a + x) * y == d and (b + x) * y == e and ((c + x) * y == f):
				return 2
	return -1

def func231(a, d, b, e, c, f):
	x = e - b
	if a + x != 0 and d % (a + x) == 0:
		y = d // (a + x)
		if (a + x) * y == d and b + x == e and (c + x == f):
			return 2
	return -1

def func213(a, d, b, e, c, f):
	x = b * d - a * e
	if e != 0 and x % e == 0:
		x = x // e
		if a + x != 0 and d % (a + x) == 0:
			y = d // (a + x)
			if (a + x) * y == d and b * y == e and (c * y == f):
				return 2
	return -1

def func222(a, d, b, e, c, f):
	x = c * e - b * f
	if f != 0 and x % f == 0 and (c != 0) and (f % c == 0):
		x = x // f
		y = f // c
		if a + x == d and (b + x) * y == e and (c * y == f):
			return 2
	return -1

def func223(a, d, b, e, c, f):
	x = b * d - a * e
	if e - d != 0 and x % (e - d) == 0:
		x = x // (e - d)
		if a + x != 0 and d % (a + x) == 0:
			y = d // (a + x)
			if (a + x) * y == d and (b + x) * y == e and (c * y == f):
				return 2
	return -1

def func212(a, d, b, e, c, f):
	if b != 0 and c != 0 and (e % b == 0) and (f % c == 0) and (e // b == f // c):
		return 2
	return -1

def func2(a, d, b, e, c, f):
	if func212(a, d, b, e, c, f) == 2 or func212(a, d, c, f, b, e) == 2 or func212(b, e, a, d, c, f) == 2 or (func212(b, e, c, f, a, d) == 2) or (func212(c, f, a, d, b, e) == 2) or (func212(c, f, b, e, a, d) == 2):
		return 2
	if func213(a, d, b, e, c, f) == 2 or func213(a, d, c, f, b, e) == 2 or func213(b, e, a, d, c, f) == 2 or (func213(b, e, c, f, a, d) == 2) or (func213(c, f, a, d, b, e) == 2) or (func213(c, f, b, e, a, d) == 2):
		return 2
	if func222(a, d, b, e, c, f) == 2 or func222(a, d, c, f, b, e) == 2 or func222(b, e, a, d, c, f) == 2 or (func222(b, e, c, f, a, d) == 2) or (func222(c, f, a, d, b, e) == 2) or (func222(c, f, b, e, a, d) == 2):
		return 2
	if func223(a, d, b, e, c, f) == 2 or func223(a, d, c, f, b, e) == 2 or func223(b, e, a, d, c, f) == 2 or (func223(b, e, c, f, a, d) == 2) or (func223(c, f, a, d, b, e) == 2) or (func223(c, f, b, e, a, d) == 2):
		return 2
	if func231(a, d, b, e, c, f) == 2 or func231(a, d, c, f, b, e) == 2 or func231(b, e, a, d, c, f) == 2 or (func231(b, e, c, f, a, d) == 2) or (func231(c, f, a, d, b, e) == 2) or (func231(c, f, b, e, a, d) == 2):
		return 2
	if func232(a, d, b, e, c, f) == 2 or func232(a, d, c, f, b, e) == 2 or func232(b, e, a, d, c, f) == 2 or (func232(b, e, c, f, a, d) == 2) or (func232(c, f, a, d, b, e) == 2) or (func232(c, f, b, e, a, d) == 2):
		return 2
	if func233(a, d, b, e, c, f) == 2 or func233(a, d, c, f, b, e) == 2 or func233(b, e, a, d, c, f) == 2 or (func233(b, e, c, f, a, d) == 2) or (func233(c, f, a, d, b, e) == 2) or (func233(c, f, b, e, a, d) == 2):
		return 2
	return -1

def func312(a, d, b, e, c, f):
	if a != 0 and d % a == 0 and (e - b == f - c):
		return 2
	return -1

def func313(a, d, b, e, c, f):
	if a != 0 and (d + b - e) % a == 0:
		x = (d + b - e) // a
		y = f - c
		if a * x + y == d and b + y == e and (c + y == f):
			return 2
	return -1

def func321(a, d, b, e, c, f):
	if a != 0 and d % a == 0:
		x = d // a
		y = f - c
		if a * x == d and b * x == e and (c + y == f):
			return 2
	return -1

def func322(a, d, b, e, c, f):
	if a != 0 and d % a == 0:
		x = d // a
		y = f - c
		if a * x == d and b * x + y == e and (c + y == f):
			return 2
	return -1

def func323(a, d, b, e, c, f):
	if a - b != 0 and (d - e) % (a - b) == 0:
		x = (d - e) // (a - b)
		y = f - c
		if a * x + y == d and b * x + y == e and (c + y == f):
			return 2
	return -1

def func331(a, d, b, e, c, f):
	if b != 0 and e % b == 0:
		x = e // b
		y = d - a * x
		if a * x + y == d and b * x == e and (c * x == f):
			return 2
	return -1

def func332(a, d, b, e, c, f):
	if c != 0 and f % c == 0:
		x = f // c
		y = d - a * x
		if a * x + y == d and b * x + y == e and (c * x == f):
			return 2
	return -1

def func333(a, d, b, e, c, f):
	if a - b != 0 and (d - e) % (a - b) == 0:
		x = (d - e) // (a - b)
		y = d - a * x
		if a * x + y == d and b * x + y == e and (c * x + y == f):
			return 2
	return -1

def func3(a, d, b, e, c, f):
	if func312(a, d, b, e, c, f) == 2 or func312(a, d, c, f, b, e) == 2 or func312(b, e, a, d, c, f) == 2 or (func312(b, e, c, f, a, d) == 2) or (func312(c, f, a, d, b, e) == 2) or (func312(c, f, b, e, a, d) == 2):
		return 2
	if func313(a, d, b, e, c, f) == 2 or func313(a, d, c, f, b, e) == 2 or func313(b, e, a, d, c, f) == 2 or (func313(b, e, c, f, a, d) == 2) or (func313(c, f, a, d, b, e) == 2) or (func313(c, f, b, e, a, d) == 2):
		return 2
	if func321(a, d, b, e, c, f) == 2 or func321(a, d, c, f, b, e) == 2 or func321(b, e, a, d, c, f) == 2 or (func321(b, e, c, f, a, d) == 2) or (func321(c, f, a, d, b, e) == 2) or (func321(c, f, b, e, a, d) == 2):
		return 2
	if func322(a, d, b, e, c, f) == 2 or func322(a, d, c, f, b, e) == 2 or func322(b, e, a, d, c, f) == 2 or (func322(b, e, c, f, a, d) == 2) or (func322(c, f, a, d, b, e) == 2) or (func322(c, f, b, e, a, d) == 2):
		return 2
	if func323(a, d, b, e, c, f) == 2 or func323(a, d, c, f, b, e) == 2 or func323(b, e, a, d, c, f) == 2 or (func323(b, e, c, f, a, d) == 2) or (func323(c, f, a, d, b, e) == 2) or (func323(c, f, b, e, a, d) == 2):
		return 2
	if func331(a, d, b, e, c, f) == 2 or func331(a, d, c, f, b, e) == 2 or func331(b, e, a, d, c, f) == 2 or (func331(b, e, c, f, a, d) == 2) or (func331(c, f, a, d, b, e) == 2) or (func331(c, f, b, e, a, d) == 2):
		return 2
	if func332(a, d, b, e, c, f) == 2 or func332(a, d, c, f, b, e) == 2 or func332(b, e, a, d, c, f) == 2 or (func332(b, e, c, f, a, d) == 2) or (func332(c, f, a, d, b, e) == 2) or (func332(c, f, b, e, a, d) == 2):
		return 2
	if func333(a, d, b, e, c, f) == 2:
		return 2
	return -1

def func412(a, d, b, e, c, f):
	if a != 0 and b != 0 and (c != 0) and (e % b == 0) and (f % c == 0) and (d % a == 0) and (e // b == f // c):
		return 2
	return -1

def func413(a, d, b, e, c, f):
	if a != 0 and b != 0 and (c != 0) and (d % a == 0) and (e % b == 0) and (f % c == 0) and (f // c == e // b):
		y = f // c
		d = d // a
		if y != 0 and d % y == 0:
			return 2
	return -1

def func422(a, d, b, e, c, f):
	if a != 0 and b != 0 and (c != 0) and (f % c == 0) and (e % b == 0):
		x = e // b
		y = f // c
		if a * x * y == d:
			return 2
	return -1

def func423(a, d, b, e, c, f):
	if c != 0 and f % c == 0:
		y = f // c
		if y != 0 and b != 0 and (e % (b * y) == 0):
			x = e // (b * y)
			if a * x * y == d and b * x * y == e and (c * y == f):
				return 2
	return -1

def func4(a, d, b, e, c, f):
	if func412(a, d, b, e, c, f) == 2 or func412(a, d, c, f, b, e) == 2 or func412(b, e, a, d, c, f) == 2 or (func412(b, e, c, f, a, d) == 2) or (func412(c, f, a, d, b, e) == 2) or (func412(c, f, b, e, a, d) == 2):
		return 2
	if func413(a, d, b, e, c, f) == 2 or func413(a, d, c, f, b, e) == 2 or func413(b, e, a, d, c, f) == 2 or (func413(b, e, c, f, a, d) == 2) or (func413(c, f, a, d, b, e) == 2) or (func413(c, f, b, e, a, d) == 2):
		return 2
	if func422(a, d, b, e, c, f) == 2 or func422(a, d, c, f, b, e) == 2 or func422(b, e, a, d, c, f) == 2 or (func422(b, e, c, f, a, d) == 2) or (func422(c, f, a, d, b, e) == 2) or (func422(c, f, b, e, a, d) == 2):
		return 2
	if func423(a, d, b, e, c, f) == 2 or func423(a, d, c, f, b, e) == 2 or func423(b, e, a, d, c, f) == 2 or (func423(b, e, c, f, a, d) == 2) or (func423(c, f, a, d, b, e) == 2) or (func423(c, f, b, e, a, d) == 2):
		return 2
	if a != 0 and b != 0 and (c != 0) and (d % a == 0) and (e % b == 0) and (f % c == 0) and (d // a == e // b) and (e // b == f // c):
		return 2
	return -1
for _ in range(int(input())):
	(a, b, c) = list(map(int, input().split()))
	(d, e, f) = list(map(int, input().split()))
	(d1, d2, d3) = (d - a, e - b, f - c)
	if d1 == 0 and d2 == 0 and (d3 == 0):
		print(0)
	elif d1 == d2 and d2 == d3 or (d1 == 0 and d2 == d3) or (d2 == 0 and d1 == d3) or (d3 == 0 and d1 == d2) or (d1 == 0 and d2 == 0 and (d3 != 0)) or (d2 == 0 and d3 == 0 and (d1 != 0)) or (d2 != 0 and d1 == 0 and (d3 == 0)):
		print(1)
	elif gunc(a, d, b, e, c, f, d1, d2, d3) == 1:
		print(1)
	elif func1(d1, d2, d3) == 2:
		print(2)
	elif func2(a, d, b, e, c, f) == 2:
		print(2)
	elif func3(a, d, b, e, c, f) == 2:
		print(2)
	elif func4(a, d, b, e, c, f) == 2:
		print(2)
	else:
		print(3)


import math
dpkg = 12345
ab = 8845
for _ in range(int(input())):
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	x = a - p
	y = b - q
	z = c - r
	ans = 3
	if p == a and q == b and (r == c):
		ans = 0
	if ans != 0:
		if a == 0 and b == 0 and (c == 0):
			ans = 1
		if p == a and q == b or (q == b and r == c) or (r == c and p == a) or (x == y and z == 0) or (y == z and x == 0) or (z == x and y == 0) or (x == y and y == z and (z == x)):
			ans = 1
		if p == a or q == b or r == c:
			if p == a:
				if q - b == r - c:
					ans = 1
				elif q != 0 and b % q == 0 and (r != 0) and (c % r == 0) and (b / q == c / r):
					ans = 1
			elif q == b:
				if p - a == r - c:
					ans == 1
				elif p != 0 and a % p == 0 and (r != 0) and (c % r == 0) and (a / p == c / r):
					ans = 1
			elif p - a == q - b:
				ans = 1
			elif q != 0 and b % q == 0 and (p != 0) and (a % p == 0) and (b / q == a / p):
				ans = 1
		if p - a == q - b and q - b == r - c or (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)):
			ans = 1
	if ans != 1 and ans != 0:
		if a == p or b == q or c == r:
			ans = 2
		if x + y == z or x + z == y or y + z == x or (x == y) or (y == z) or (z == x):
			ans = 2
		if p != 0 and q != 0 and (r != 0):
			if a % p == 0 and b % q == 0 and (c % r == 0):
				x = a / p
				y = b / q
				z = c / r
				if x * y == z or x * z == y or y * z == x or (x == y) or (y == z) or (z == x):
					ans = 2
		factors = []
		for i in range(1, int(math.sqrt(abs(a))) + 1):
			if a % i == 0:
				if a / i == i:
					factors.append(i)
					factors.append(-i)
				else:
					factors.append(i)
					factors.append(-i)
					factors.append(a // i)
					factors.append(-1 * (a // i))
		for i in range(1, int(math.sqrt(abs(b))) + 1):
			if b % i == 0:
				if b / i == i:
					factors.append(i)
					factors.append(-i)
				else:
					factors.append(i)
					factors.append(-i)
					factors.append(b // i)
					factors.append(-1 * (b // i))
		for i in range(1, int(math.sqrt(abs(c))) + 1):
			if c % i == 0:
				if c / i == i:
					factors.append(i)
					factors.append(-i)
				else:
					factors.append(i)
					factors.append(-i)
					factors.append(c // i)
					factors.append(-1 * (c // i))
		for i in factors:
			if a % i == 0:
				x = a / i - p
			else:
				x = a - p
			if b - q == x or (b % i == 0 and (b / i - q == 0 or b / i - q == x)):
				if c - r == x or (c % i == 0 and (c / i - r == 0 or c / i - r == x)):
					ans = 2
			if b % i == 0:
				x = b / i - q
			else:
				x = b - q
			if a - p == x or (a % i == 0 and (a / i - p == 0 or a / i - p == x)):
				if c - r == x or (c % i == 0 and (c / i - r == 0 or c / i - r == x)):
					ans = 2
			if c % i == 0:
				x = c / i - r
			else:
				x = c - r
			if a - p == x or (a % i == 0 and (a / i - p == 0 or a / i - p == x)):
				if b - q == x or (b % i == 0 and (b / i - q == 0 or b / i - q == x)):
					ans = 2
		a1 = q - p
		b1 = r - q
		c1 = p - r
		x = b - a
		y = c - b
		z = a - c
		if a1 != 0:
			if x % a1 == 0:
				k = x // a1
				d = a - k * p
				if r * k + d == c or r * k == c or r + d == c:
					ans = 2
		if b1 != 0:
			if y % b1 == 0:
				k = y // b1
				d = b - k * q
				if p * k + d == a or p * k == a or p + d == a:
					ans = 2
		if c1 != 0:
			if z % c1 == 0:
				k = z // c1
				d = c - k * r
				if q * k + d == b or q * k == b or q + d == b:
					ans = 2
		d = a - p
		if q != 0 and (b - d) % q == 0:
			k = (b - d) // q
			if r * k == c or r * k + d == c:
				ans = 2
		if q != 0 and b % q == 0:
			k = b // q
			if r * k == c or r * k + d == c:
				ans = 2
		d = b - q
		if r != 0 and (c - d) % r == 0:
			k = (c - d) // r
			if p * k == a or p * k + d == a:
				ans = 2
		if r != 0 and c % r == 0:
			k = c // r
			if p * k == a or p * k + d == a:
				ans = 2
		d = c - r
		if p != 0 and (a - d) % p == 0:
			k = (a - d) // p
			if q * k == b or q * k + d == b:
				ans = 2
		if p != 0 and a % p == 0:
			k = a // p
			if q * k == b or q * k + d == b:
				ans = 2
	print(ans)


from math import *

def one_zero(p, q, r, a, b, c):
	if add_all(p, q, r, a, b, c):
		return 1
	if add_two_one_zero(p, q, r, a, b, c):
		return 1
	if add_two_one_zero(p, r, q, a, c, b):
		return 1
	if add_two_one_zero(r, q, p, c, b, a):
		return 1
	if add_one_two_zero(p, q, r, a, b, c):
		return 1
	if add_one_two_zero(q, r, p, b, c, a):
		return 1
	if add_one_two_zero(r, q, p, c, b, a):
		return 1
	if multiply_two_one_zero(p, q, r, a, b, c):
		return 1
	if isTwo(p, q, r, a, b, c):
		return 2
	count = 3
	if c == 0:
		count -= 1
	return count

def two_zero(p, q, r, a, b, c):
	if add_all(p, q, r, a, b, c):
		return 1
	if add_two_one_zero(p, q, r, a, b, c):
		return 1
	if add_two_one_zero(p, r, q, a, c, b):
		return 1
	if add_two_one_zero(r, q, p, c, b, a):
		return 1
	if add_one_two_zero(p, q, r, a, b, c):
		return 1
	if add_one_two_zero(q, r, p, b, c, a):
		return 1
	if add_one_two_zero(r, q, p, c, b, a):
		return 1
	count = 3
	if p == 0 and a == 0:
		count -= 1
	if q == 0 and b == 0:
		count -= 1
	if r == 0 and c == 0:
		count -= 1
	return count

def add_all(p, q, r, a, b, c):
	if a - p == b - q and b - q == c - r:
		return True

def multiply_all(p, q, r, a, b, c):
	try:
		x = a // p
		if p * x == a and q * x == b and (r * x == c):
			return True
	except:
		pass

def add_two_one_zero(p, q, r, a, b, c):
	if c == r:
		if a - p == b - q:
			return True

def multiply_two_one_zero(p, q, r, a, b, c):
	try:
		if c == r:
			x = a // p
			if p * x == a and q * x == b:
				return True
	except:
		pass

def add_one_two_zero(p, q, r, a, b, c):
	if c == r and b == q:
		return True

def multiply_two_add_all(p, q, r, a, b, c):
	try:
		y = c - r
		x = (a - y) // p
		if p * x + y == a and q * x + y == b and (r + y == c):
			return True
	except:
		pass

def multiply_one_add_all(p, q, r, a, b, c):
	try:
		y = b - q
		x = (a - y) // p
		if p * x + y == a and q + y == b and (r + y == c):
			return True
	except:
		pass

def add_two_multiply_all(p, q, r, a, b, c):
	try:
		y = c // r
		x = a // y - p
		if (p + x) * y == a and (q + x) * y == b and (r * y == c):
			return True
	except:
		pass

def add_one_multiply_all(p, q, r, a, b, c):
	try:
		y = b // q
		x = a // y - p
		if (p + x) * y == a and q * y == b and (r * y == c):
			return True
	except:
		pass

def multiply_all_add_two(p, q, r, a, b, c):
	try:
		x = a // p
		y = c - r * x
		if p * x == a and q * x + y == b and (r * x + y == c):
			return True
	except:
		pass

def multiply_all_add_one(p, q, r, a, b, c):
	try:
		x = c // r
		y = a - p * x
		if p * x + y == a and q * x == b and (r * x == c):
			return True
	except:
		pass

def add_all_multiply_two(p, q, r, a, b, c):
	try:
		x = a - p
		y = b // (q + x)
		if p + x == a and (q + x) * y == b and ((r + x) * y == c):
			return True
	except:
		pass

def add_all_multiply_one(p, q, r, a, b, c):
	try:
		x = b - q
		y = a // (p + x)
		if (p + x) * y == a and q + x == b and (r + x == c):
			return True
	except:
		pass

def multiply_two_add_two(p, q, r, a, b, c):
	try:
		if r == c:
			x = (a - b) // (p - q)
			y = a - p * x
			if p * x + y == a and q * x + y == b:
				return True
	except:
		pass
	try:
		x = b // q
		y = c - r
		if p * x + y == a and q * x == b and (r + y == c):
			return True
	except:
		pass

def multiply_two_add_one(p, q, r, a, b, c):
	try:
		if c == r:
			x = b // q
			y = a - p * x
			if p * x + y and q * x == b:
				return True
	except:
		pass
	try:
		x = a // p
		y = c - r
		if p * x == a and q * x == b and (r + y == c):
			return True
	except:
		pass

def multiply_one_add_two(p, q, r, a, b, c):
	try:
		if r == c:
			y = b - q
			x = (a - y) // p
			if p * x + y == a and q + y == b:
				return True
	except:
		pass
	try:
		y = b - q
		x = a // p
		if p * x == a and q + y == b and (r + y == c):
			return True
	except:
		pass

def multiply_one_add_one(p, q, r, a, b, c):
	try:
		if r == c:
			y = b - q
			x = a // p
			if p * x == a and q + y == b:
				return True
	except:
		pass

def add_one_multiply_two(p, q, r, a, b, c):
	try:
		if c == r:
			x = b // q
			y = a // x - p
			if (p + y) * x == a and q * x == b:
				return True
	except:
		pass
	try:
		y = a - p
		x = b // q
		if p + y == a and q * x == b and (r * x == c):
			return True
	except:
		pass

def add_two_multiply_two(p, q, r, a, b, c):
	try:
		if r == c:
			y = (a - b) // (p - q)
			x = a // y - p
			if p * x + y == a and q * x + y == b:
				return True
	except:
		pass
	try:
		y = c - r
		x = b // q
		if (p + y) * x == a and q * x == b and (r + y == c):
			return True
	except:
		pass

def add_two_multiply_one(p, q, r, a, b, c):
	try:
		if c == r:
			x = b - q
			y = a // (p + x)
			if (p + x) * y == a and q + x == b:
				return True
	except:
		pass
	try:
		y = c // r
		x = b - q
		if p + x == a and q + x == b and (r * y == c):
			return True
	except:
		pass

def add_one_multiply_one(p, q, r, a, b, c):
	try:
		if c == r:
			x = a // p
			y = b - q
			if p * x == a and q + y == b:
				return True
	except:
		pass

def one_zero_add_two(p, q, r, a, b, c):
	if c == r:
		return True

def add_two_add_one(p, q, r, a, b, c):
	if a - p == b - q:
		return True

def add_two_add_two(p, q, r, a, b, c):
	y = b - q
	x = c - r
	if p + x + y == a and q + y == b and (r + x == c):
		return True

def multiply_two_multiply_two(p, q, r, a, b, c):
	try:
		y = b // q
		x = c // r
		if p * x * y == a and q * y == b and (r * x == c):
			return True
	except:
		pass

def isTwo(p, q, r, a, b, c):
	try:
		x = (a - b) // (p - q)
		y = a - p * x
		if p * x + y == a and q * x + y == b and (r * x + y == c):
			return True
	except:
		pass
	ans = multiply_two_add_all(p, q, r, a, b, c)
	if ans:
		return True
	ans = multiply_two_add_all(p, r, q, a, c, b)
	if ans:
		return True
	ans = multiply_two_add_all(r, q, p, c, b, a)
	if ans:
		return True
	ans = multiply_one_add_all(p, q, r, a, b, c)
	if ans:
		return True
	ans = multiply_one_add_all(q, p, r, b, a, c)
	if ans:
		return True
	ans = multiply_one_add_all(r, q, p, c, b, a)
	if ans:
		return True
	try:
		y = (a - b) // (p - q)
		x = a // y - p
		if (p + x) * y == a and (q + x) * y == b and ((r + x) * y == c):
			return True
	except:
		pass
	ans = add_two_multiply_all(p, q, r, a, b, c)
	if ans:
		return True
	ans = add_two_multiply_all(p, r, q, a, c, b)
	if ans:
		return True
	ans = add_two_multiply_all(r, q, p, c, b, a)
	if ans:
		return True
	ans = add_one_multiply_all(p, q, r, a, b, c)
	if ans:
		return True
	ans = add_one_multiply_all(q, p, r, b, a, c)
	if ans:
		return True
	ans = add_one_multiply_all(r, q, p, c, b, a)
	if ans:
		return True
	ans = multiply_all_add_two(p, q, r, a, b, c)
	if ans:
		return True
	ans = multiply_all_add_two(q, p, r, b, a, c)
	if ans:
		return True
	ans = multiply_all_add_two(r, q, p, c, b, a)
	if ans:
		return True
	ans = multiply_all_add_one(p, q, r, a, b, c)
	if ans:
		return True
	ans = multiply_all_add_one(q, p, r, b, a, c)
	if ans:
		return True
	ans = multiply_all_add_one(r, q, p, c, b, a)
	if ans:
		return True
	ans = add_all_multiply_two(p, q, r, a, b, c)
	if ans:
		return True
	ans = add_all_multiply_two(q, p, r, b, a, c)
	if ans:
		return True
	ans = add_all_multiply_two(r, q, p, c, b, a)
	if ans:
		return True
	ans = add_all_multiply_one(p, q, r, a, b, c)
	if ans:
		return True
	ans = add_all_multiply_one(q, p, r, b, a, c)
	if ans:
		return True
	ans = add_all_multiply_one(r, q, p, c, b, a)
	if ans:
		return True
	ans = multiply_two_add_two(p, q, r, a, b, c)
	if ans:
		return True
	ans = multiply_two_add_two(p, r, q, a, c, b)
	if ans:
		return True
	ans = multiply_two_add_two(q, p, r, b, a, c)
	if ans:
		return True
	ans = multiply_two_add_two(q, r, p, b, c, a)
	if ans:
		return True
	ans = multiply_two_add_two(r, q, p, c, b, a)
	if ans:
		return True
	ans = multiply_two_add_two(r, p, q, c, a, b)
	if ans:
		return True
	ans = multiply_two_add_one(p, q, r, a, b, c)
	if ans:
		return True
	ans = multiply_two_add_one(p, r, q, a, c, b)
	if ans:
		return True
	ans = multiply_two_add_one(q, p, r, b, a, c)
	if ans:
		return True
	ans = multiply_two_add_one(q, r, p, b, c, a)
	if ans:
		return True
	ans = multiply_two_add_one(r, q, p, c, b, a)
	if ans:
		return True
	ans = multiply_two_add_one(r, p, q, c, a, b)
	if ans:
		return True
	ans = multiply_one_add_two(p, q, r, a, b, c)
	if ans:
		return True
	ans = multiply_one_add_two(p, r, q, a, c, b)
	if ans:
		return True
	ans = multiply_one_add_two(q, p, r, b, a, c)
	if ans:
		return True
	ans = multiply_one_add_two(q, r, p, b, c, a)
	if ans:
		return True
	ans = multiply_one_add_two(r, q, p, c, b, a)
	if ans:
		return True
	ans = multiply_one_add_two(r, p, q, c, a, b)
	if ans:
		return True
	ans = multiply_one_add_one(p, q, r, a, b, c)
	if ans:
		return True
	ans = multiply_one_add_one(p, r, q, a, c, b)
	if ans:
		return True
	ans = multiply_one_add_one(q, p, r, b, a, c)
	if ans:
		return True
	ans = multiply_one_add_one(q, r, p, b, c, a)
	if ans:
		return True
	ans = multiply_one_add_one(r, q, p, c, b, a)
	if ans:
		return True
	ans = multiply_one_add_one(r, p, q, c, a, b)
	if ans:
		return True
	ans = add_one_multiply_two(p, q, r, a, b, c)
	if ans:
		return True
	ans = add_one_multiply_two(p, r, q, a, c, b)
	if ans:
		return True
	ans = add_one_multiply_two(q, p, r, b, a, c)
	if ans:
		return True
	ans = add_one_multiply_two(q, r, p, b, c, a)
	if ans:
		return True
	ans = add_one_multiply_two(r, q, p, c, b, a)
	if ans:
		return True
	ans = add_one_multiply_two(r, p, q, c, a, b)
	if ans:
		return True
	ans = add_two_multiply_two(p, q, r, a, b, c)
	if ans:
		return True
	ans = add_two_multiply_two(p, r, q, a, c, b)
	if ans:
		return True
	ans = add_two_multiply_two(q, p, r, b, a, c)
	if ans:
		return True
	ans = add_two_multiply_two(q, r, p, b, c, a)
	if ans:
		return True
	ans = add_two_multiply_two(r, q, p, c, b, a)
	if ans:
		return True
	ans = add_two_multiply_two(r, p, q, c, a, b)
	if ans:
		return True
	ans = add_two_multiply_one(p, q, r, a, b, c)
	if ans:
		return True
	ans = add_two_multiply_one(p, r, q, a, c, b)
	if ans:
		return True
	ans = add_two_multiply_one(q, p, r, b, a, c)
	if ans:
		return True
	ans = add_two_multiply_one(q, r, p, b, c, a)
	if ans:
		return True
	ans = add_two_multiply_one(r, q, p, c, b, a)
	if ans:
		return True
	ans = add_two_multiply_one(r, p, q, c, a, b)
	if ans:
		return True
	ans = add_one_multiply_one(p, q, r, a, b, c)
	if ans:
		return True
	ans = add_one_multiply_one(p, r, q, a, c, b)
	if ans:
		return True
	ans = add_one_multiply_one(q, p, r, b, a, c)
	if ans:
		return True
	ans = add_one_multiply_one(q, r, p, b, c, a)
	if ans:
		return True
	ans = add_one_multiply_one(r, q, p, c, b, a)
	if ans:
		return True
	ans = add_one_multiply_one(r, p, q, c, a, b)
	if ans:
		return True
	ans = add_two_add_two(p, q, r, a, b, c)
	if ans:
		return True
	ans = add_two_add_two(q, p, r, b, a, c)
	if ans:
		return True
	ans = add_two_add_two(r, q, p, c, b, a)
	if ans:
		return True
	ans = multiply_two_multiply_two(p, q, r, a, b, c)
	if ans:
		return True
	ans = multiply_two_multiply_two(q, p, r, b, a, c)
	if ans:
		return True
	ans = multiply_two_multiply_two(r, q, p, c, b, a)
	if ans:
		return True
	ans = one_zero_add_two(p, q, r, a, b, c)
	if ans:
		return True
	ans = one_zero_add_two(p, r, q, a, c, b)
	if ans:
		return True
	ans = one_zero_add_two(q, p, r, b, a, c)
	if ans:
		return True
	ans = one_zero_add_two(q, r, p, b, c, a)
	if ans:
		return True
	ans = one_zero_add_two(r, q, p, c, b, a)
	if ans:
		return True
	ans = one_zero_add_two(r, p, q, c, a, b)
	if ans:
		return True
	ans = add_two_add_one(p, q, r, a, b, c)
	if ans:
		return True
	ans = add_two_add_one(p, r, q, a, c, b)
	if ans:
		return True
	ans = add_two_add_one(r, q, p, c, b, a)
	if ans:
		return True
	return False

def isOne(p, q, r, a, b, c):
	ans = add_all(p, q, r, a, b, c)
	if ans:
		return True
	ans = multiply_all(p, q, r, a, b, c)
	if ans:
		return True
	ans = add_two_one_zero(p, q, r, a, b, c)
	if ans:
		return True
	ans = add_two_one_zero(r, q, p, c, b, a)
	if ans:
		return True
	ans = add_two_one_zero(p, r, q, a, c, b)
	if ans:
		return True
	ans = multiply_two_one_zero(p, q, r, a, b, c)
	if ans:
		return True
	ans = multiply_two_one_zero(r, q, p, c, b, a)
	if ans:
		return True
	ans = multiply_two_one_zero(p, r, q, a, c, b)
	if ans:
		return True
	ans = add_one_two_zero(p, q, r, a, b, c)
	if ans:
		return True
	ans = add_one_two_zero(r, q, p, c, b, a)
	if ans:
		return True
	ans = add_one_two_zero(q, p, r, b, a, c)
	if ans:
		return True
for _ in range(int(input())):
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	if p == a and q == b and (r == c):
		print(0)
		continue
	if p == 0 and q != 0 and (r != 0):
		print(one_zero(r, q, p, c, b, a))
		continue
	if q == 0 and p != 0 and (r != 0):
		print(one_zero(p, r, q, a, c, b))
		continue
	if r == 0 and p != 0 and (q != 0):
		print(one_zero(p, q, r, a, b, c))
		continue
	if [p, q, r].count(0) == 2:
		print(two_zero(p, q, r, a, b, c))
		continue
	if isOne(p, q, r, a, b, c):
		print(1)
	elif isTwo(p, q, r, a, b, c):
		print(2)
	else:
		print(3)


T = int(input())
for tc in range(T):
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	p_diff = a - p
	q_diff = b - q
	r_diff = c - r
	flag = 0

	def gcd(a, b):
		if b == 0:
			return a
		else:
			return gcd(b, a % b)
	g_c_d = gcd(a, gcd(b, c))

	def factors(x):
		result = []
		i = 2
		while i * i <= x:
			if x % i == 0:
				result.append(i)
				if x // i != i:
					result.append(x // i)
			i += 1
		return result
	listi = factors(g_c_d)
	try:
		p_rem = a / p
	except:
		p_rem = 1
	try:
		q_rem = b / q
	except:
		q_rem = 1
	try:
		r_rem = c / r
	except:
		r_rem = 1
	if a == p and b == q and (c == r):
		print('0')
		flag = 1
		continue
	elif p_rem == q_rem == r_rem != 1:
		print('1')
		flag = 1
		continue
	elif p_diff == q_diff == r_diff:
		print('1')
		flag = 1
		continue
	elif p == a and q == b:
		print('1')
		flag = 1
		continue
	elif p == a and r == c:
		print('1')
		flag = 1
		continue
	elif q == b and r == c:
		print('1')
		continue
	elif p == a:
		if q_diff == r_diff:
			print('1')
			flag = 1
			continue
		elif q_rem == r_rem != 1:
			print('1')
			flag = 1
			continue
		else:
			print('2')
			flag = 1
			continue
	elif q == b:
		if p_diff == r_diff:
			print('1')
			flag = 1
			continue
		elif p_rem == r_rem != 1:
			print('1')
			flag = 1
			continue
		else:
			print('2')
			flag = 1
			continue
	elif r == c:
		if q_diff == p_diff:
			print('1')
			flag = 1
		elif q_rem == p_rem != 1:
			print('1')
			flag = 1
			continue
		else:
			print('2')
			flag = 1
	elif p_diff == 0:
		if q_diff == r_diff:
			print('1')
			flag = 1
			continue
		elif q_rem == r_rem:
			print('1')
			flag = 1
			continue
		else:
			print('2')
			flag = 1
			continue
	elif q_diff == 0:
		if p_diff == r_diff:
			print('1')
			flag = 1
			continue
		elif p_rem == r_rem:
			print('1')
			flag = 1
			continue
		else:
			print('2')
			flag = 1
			continue
	elif r_diff == 0:
		if p_diff == q_diff:
			print('1')
			flag = 1
			continue
		elif p_rem == q_rem:
			print('1')
			flag = 1
			continue
		else:
			print('2')
			flag = 1
			continue
	elif r_diff - p_diff == q_diff:
		print('2')
		continue
	elif r_diff - q_diff == p_diff:
		print('2')
		continue
	elif q_diff - r_diff == p_diff:
		print('2')
		continue
	elif q_diff - p_diff == r_diff:
		print('2')
		continue
	elif p_diff - q_diff == r_diff:
		print('2')
		continue
	elif p_diff - r_diff == q_diff:
		print('2')
		continue
	elif p_diff == q_diff:
		print('2')
		flag = 1
		continue
	elif q_diff == r_diff:
		print('2')
		flag = 1
		continue
	elif p_diff == r_diff:
		print('2')
		flag = 1
		continue
	elif p_rem == q_rem and r_rem != 1:
		print('2')
		flag = 1
		continue
	elif p_rem == r_rem and q_rem != 1:
		print('2')
		flag = 1
		continue
	elif q_rem == r_rem and p_rem != 1:
		print('2')
		flag = 1
		continue
	elif a // g_c_d - p == b // g_c_d - q == c // g_c_d - r:
		print('2')
		flag = 1
		continue
	if flag == 0:
		try:
			if (r_diff - b) / q == (r_diff - a) / p:
				print('2')
				flag = 1
				continue
		except:
			if (r_diff - b) / 1 == (r_diff - a) / 1:
				print('2')
				flag = 1
				continue
		try:
			if (q_diff - c) / r == (q_diff - a) / p:
				print('2')
				flag = 1
				continue
		except:
			if (q_diff - c) / 1 == (q_diff - a) / 1:
				print('2')
				flag = 1
				continue
		try:
			if (p_diff - c) / r == (p_diff - b) / q:
				print('2')
				flag = 1
				continue
		except:
			if (p_diff - c) / 1 == (p_diff - b) / 1:
				print('2')
				flag = 1
				continue
		try:
			if b / r_rem - q == a - p:
				print('2')
				flag = 1
				continue
		except:
			if b / 1 - q == a - p:
				print('2')
				flag = 1
				continue
		try:
			if a / r_rem - p == b - q:
				print('2')
				flag = 1
				continue
		except:
			if a / 1 - p == b - q:
				print('2')
				flag = 1
				continue
		try:
			if b / p_rem - q == c - r:
				print('2')
				flag = 1
				continue
		except:
			if b / 1 - q == c - r:
				print('2')
				flag = 1
				continue
		try:
			if c / p_rem - r == b - q:
				print('2')
				flag = 1
				continue
		except:
			if c / 1 - r == b - q:
				print('2')
				flag = 1
				continue
		try:
			if c / q_rem - r == a - p:
				print('2')
				flag = 1
				continue
		except:
			if c / 1 - r == a - p:
				print('2')
				flag = 1
				continue
		try:
			if a / q_rem - p == c - r:
				print('2')
				flag = 1
				continue
		except:
			if a / 1 - p == c - r:
				print('2')
				flag = 1
				continue
	if flag == 0:
		try:
			if (b - (c - r)) / q == p_rem:
				print('2')
				flag = 1
				continue
		except:
			x = 1
			if (b - (c - r)) / x == p_rem:
				print('2')
				flag = 1
				continue
		try:
			if (b - (a - p)) / q == r_rem:
				print('2')
				flag = 1
				continue
		except:
			x = 1
			if (b - (a - p)) / x == r_rem:
				print('2')
				flag = 1
				continue
		try:
			if (a - (b - q)) / p == r_rem:
				print('2')
				flag = 1
				continue
		except:
			x = 1
			if (a - (b - q)) / x == r_rem:
				print('2')
				flag = 1
				continue
		try:
			if (a - (c - r)) / p == q_rem:
				print('2')
				flag = 1
				continue
		except:
			x = 1
			if (a - (c - r)) / x == q_rem:
				print('2')
				flag = 1
				continue
		try:
			if (c - (b - q)) / r == p_rem:
				print('2')
				flag = 1
				continue
		except:
			x = 1
			if (c - (b - q)) / x == p_rem:
				print('2')
				flag = 1
				continue
		try:
			if (c - (a - p)) / r == q_rem:
				print('2')
				flag = 1
				continue
		except:
			x = 1
			if (c - (a - p)) / x == q_rem:
				print('2')
				flag = 1
				continue
		try:
			if b / r_rem / q == p_rem:
				print('2')
				flag = 1
				continue
		except:
			x = 1
			if b / x / x == p_rem:
				print('2')
				flag = 1
				continue
		try:
			if a / r_rem / p == q_rem:
				print('2')
				flag = 1
				continue
		except:
			x = 1
			if a / x / x == q_rem:
				print('2')
				flag = 1
				continue
		try:
			if b / p_rem / q == r_rem:
				print('2')
				flag = 1
				continue
		except:
			x = 1
			if b / x / x == r_rem:
				print('2')
				flag = 1
				continue
		try:
			if c / p_rem / r == q_rem:
				print('2')
				flag = 1
				continue
		except:
			x = 1
			if c / x / x == q_rem:
				print('2')
				flag = 1
				continue
		try:
			if a / q_rem / p == r_rem:
				print('2')
				flag = 1
				continue
		except:
			x = 1
			if a / x / x == r_rem:
				print('2')
				flag = 1
				continue
		try:
			if c / q_rem / r == p_rem:
				print('2')
				flag = 1
				continue
		except:
			x = 1
			if c / x / x == p_rem:
				print('2')
				flag = 1
				continue
	if flag == 0:
		try:
			if b / (q + (c - r)) == a / (p + (c - r)):
				print('2')
				flag = 1
				continue
		except:
			rem1 = 1
			rem2 = 1
			if b / rem1 == a / rem2:
				print('2')
				flag = 1
				continue
		try:
			if c / (r + (b - q)) == a / (p + (b - q)):
				print('2')
				flag = 1
				continue
		except:
			rem1 = 1
			rem2 = 1
			if c / rem1 == a / rem2:
				print('2')
				flag = 1
				continue
		try:
			if b / (q + (a - p)) == c / (r + (a - p)):
				print('2')
				flag = 1
				continue
		except:
			rem1 = 1
			rem2 = 1
			if b / rem1 == c / rem2:
				print('2')
				flag = 1
				continue
	if flag == 0:
		if p - q != 0:
			rem = (a - b) / (p - q)
			diff = a - p * rem
			if rem % 1 == 0 and diff % 1 == 0 and (r * rem + diff == c):
				print('2')
				flag = 1
	if flag == 0:
		if len(listi) > 0:
			for x in listi:
				if a // x - p == b // x - q == c // x - r:
					print('2')
					flag = 1
	if flag == 0:
		if a - q_rem * p == c - q_rem * r:
			print('2')
			flag = 1
			continue
		elif a - r_rem * p == b - r_rem * q:
			print('2')
			flag = 1
			continue
		elif c - p_rem * r == b - p_rem * q:
			print('2')
			flag = 1
			continue
	if flag == 0:
		print('3')


t = int(input())
for test in range(0, t):
	(a, b, c) = input().split(' ')
	(x, y, z) = input().split(' ')
	a = int(a)
	b = int(b)
	c = int(c)
	x = int(x)
	y = int(y)
	z = int(z)
	if a == x and b == y and (c == z):
		print(0)
	elif a == x and b == y or (c == z and b == y) or (a == x and c == z):
		print(1)
	elif a == x or b == y or c == z:
		if a == x:
			if y - b == z - c or (b * c != 0 and y % b == 0 and (c * (y // b) == z)):
				print(1)
			else:
				print(2)
		elif b == y:
			if x - a == z - c or (a * c != 0 and x % a == 0 and (c * (x // a) == z)):
				print(1)
			else:
				print(2)
		elif y - b == x - a or (b * a != 0 and y % b == 0 and (a * (y // b) == x)):
			print(1)
		else:
			print(2)
	elif x - a == y - b and x - a == z - c:
		print(1)
	elif a * b * c != 0 and x % a == 0 and (x // a * b == y) and (x // a * c == z):
		print(1)
	else:
		ma = mb = mc = 0
		if a != 0 and x % a == 0:
			ma = 1
		if b != 0 and y % b == 0:
			mb = 1
		if c != 0 and z % c == 0:
			mc = 1
		if a != b:
			d2 = (a * y - b * x) / (a - b)
			d1 = (x - y) / (a - b)
			if d1 % 1 == 0 and d2 % 1 == 0 and (c * d1 + d2 == z or c * d1 == z or c + d2 == z):
				print(2)
				continue
		elif x == y:
			print(2)
			continue
		if c != b:
			d2 = (c * y - b * z) / (c - b)
			d1 = (z - y) / (c - b)
			if d1 % 1 == 0 and d2 % 1 == 0 and (a * d1 + d2 == x or a * d1 == x or a + d2 == x):
				print(2)
				continue
		elif z == y:
			print(2)
			continue
		if a != c:
			d2 = (a * z - c * x) / (a - c)
			d1 = (x - z) / (a - c)
			if d1 % 1 == 0 and d2 % 1 == 0 and (b * d1 + d2 == y or b * d1 == y or b + d2 == y):
				print(2)
				continue
		elif x == z:
			print(2)
			continue
		if mc and mb:
			if y // b * c == z:
				print(2)
				continue
		if ma and mc:
			if x // a * c == z:
				print(2)
				continue
		if ma and mb:
			if x // a * b == y:
				print(2)
				continue
		if mb:
			if a * (y // b) + (z - c) == x or c * (y // b) + (x - a) == z:
				print(2)
				continue
		if mc:
			if a * (z // c) + (y - b) == x or b * (z // c) + (x - a) == y:
				print(2)
				continue
		if ma:
			if b * (x // a) + (z - c) == y or c * (x // a) + (y - b) == z:
				print(2)
				continue
		if y - b == z - c or y - b == x - a or x - a == z - c:
			print(2)
			continue
		if a != b and x != y:
			d1 = (a * y - b * x) / (x - y)
			d2 = (x - y) / (a - b)
			if d1 % 1 == 0 and d2 % 1 == 0 and ((c + d1) * d2 == z or c + d1 == z or c * d2 == z):
				print(2)
				continue
		if a != c and x != z:
			d1 = (a * z - c * x) / (x - z)
			d2 = (x - z) / (a - c)
			if d1 % 1 == 0 and d2 % 1 == 0 and ((b + d1) * d2 == y or b + d1 == y or b * d2 == y):
				print(2)
				continue
		if c != b and z != y:
			d1 = (c * y - b * z) / (z - y)
			d2 = (z - y) / (c - b)
			if d1 % 1 == 0 and d2 % 1 == 0 and ((a + d1) * d2 == x or a + d1 == x or a * d2 == x):
				print(2)
				continue
		if mc:
			if (a + y - b) * (z // c) == x or (b + x - a) * (z // c) == y:
				print(2)
				continue
		if ma:
			if (c + y - b) * (x // a) == z or (b + z - c) * (x // a) == y:
				print(2)
				continue
		if mb:
			if (a + z - c) * (y // b) == x or (c + x - a) * (y // b) == z:
				print(2)
				continue
		if a + y - b + z - c == x or b + x - a + z - c == y or c + x - a + y - b == z:
			print(2)
			continue
		if ma and mb and mc:
			if a * (y // b) * (z // c) == x or b * (x // a) * (z // c) == y or c * (x // a) * (y // b) == z:
				print(2)
				continue
		print(3)


def eqSolve(p, a, q, b):
	x = p - q
	y = a - b
	if x != 0:
		z = int(y / x)
		return z
	else:
		return 1

def solve(p, q, r, a, b, c, rs):
	if p == a and q == b and (r == c):
		return rs
	elif rs >= 2:
		return 3
	else:
		res = 3
		m = 8
		adds = [a - p, b - q, c - r]
		muls = []
		if p != 0:
			muls.append(a / p)
		if q != 0:
			muls.append(b / q)
		if r != 0:
			muls.append(c / r)
		muls.append(eqSolve(p, a, q, b))
		muls.append(eqSolve(p, a, r, c))
		muls.append(eqSolve(q, b, r, c))
		for n in range(m):
			for add in adds:
				np = p
				nq = q
				nr = r
				if n & 1 > 0:
					np = np + add
				if n & 2 > 0:
					nq = nq + add
				if n & 4 > 0:
					nr = nr + add
				res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
			for mul in muls:
				np = p
				nq = q
				nr = r
				if n & 1 > 0:
					np = np * mul
				if n & 2 > 0:
					nq = nq * mul
				if n & 4 > 0:
					nr = nr * mul
				res = min(res, solve(np, nq, nr, a, b, c, rs + 1))
		return res
t = int(input())
x = 0
for x in range(t):
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	y = solve(p, q, r, a, b, c, 0)
	print(y)


def CheckForTwoEq(p, a, q, b):
	if p == a or q == b:
		return True
	if a - p == b - q:
		return True
	if p != 0 and q != 0 and (a % p == 0) and (b % q == 0) and (a / p == b / q):
		return True
	return False

def Ccide(p, a, q, b, r, c):
	x = b - a
	d = q - p
	if d != 0:
		y = a - 1 * p * (x / d)
		if 1 * r * (x / d) + y == c:
			if x % d == 0:
				return True
		if x % d == 0 and r + y == c:
			return True
		if x % d == 0 and r * x == c:
			return True
	return False
for _ in range(int(input())):
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	if p == a and q == b and (r == c):
		print(0)
		continue
	if p == a and CheckForTwoEq(q, b, r, c) or (q == b and CheckForTwoEq(p, a, r, c)) or (r == c and CheckForTwoEq(q, b, p, a)):
		print(1)
		continue
	diff = a - p
	if q + diff == b and r + diff == c:
		print(1)
		continue
	if p != 0 and a % p == 0:
		diff = a / p
		if q * diff == b and r * diff == c:
			print(1)
			continue
	d = 0
	if p != 0 and a % p == 0:
		d = a / p
		if CheckForTwoEq(q * d, b, r * d, c) or CheckForTwoEq(q * d, b, r, c) or CheckForTwoEq(q, b, r * d, c) or CheckForTwoEq(q, b, r, c):
			print(2)
			continue
	d = a - p
	if CheckForTwoEq(q + d, b, r + d, c) or CheckForTwoEq(q + d, b, r, c) or CheckForTwoEq(q, b, r + d, c) or CheckForTwoEq(q, b, r, c):
		print(2)
		continue
	if q != 0 and b % q == 0:
		d = b / q
		if CheckForTwoEq(p * d, a, r * d, c) or CheckForTwoEq(p * d, a, r, c) or CheckForTwoEq(p, a, r * d, c) or CheckForTwoEq(p, a, r, c):
			print(2)
			continue
	d = b - q
	if CheckForTwoEq(p + d, a, r + d, c) or CheckForTwoEq(p + d, a, r, c) or CheckForTwoEq(p, a, r + d, c) or CheckForTwoEq(p, a, r, c):
		print(2)
		continue
	if r != 0 and c % r == 0:
		d = c / r
		if CheckForTwoEq(q * d, b, p * d, a) or CheckForTwoEq(q * d, b, p, a) or CheckForTwoEq(q, b, p * d, a) or CheckForTwoEq(q, b, p, a):
			print(2)
			continue
	d = c - r
	if CheckForTwoEq(q + d, b, p + d, a) or CheckForTwoEq(q + d, b, p, a) or CheckForTwoEq(q, b, p + d, a) or CheckForTwoEq(q, b, p, a):
		print(2)
		continue
	if Ccide(p, a, q, b, r, c) or Ccide(p, a, r, c, q, b) or Ccide(q, b, r, c, p, a):
		print(2)
		continue
	print(3)


from operator import mul, add

def solve_eq(t1, t2):
	(p, a) = t1
	(q, b) = t2
	if q - p == 0:
		return 1
	return (b - a) // (q - p)

def solve0(p, q, r, a, b, c, op_count):
	if (p, q, r) == (a, b, c):
		return op_count
	if op_count >= 2:
		return 3
	soln = 3
	operations = []
	operations.append((add, a - p))
	operations.append((add, b - q))
	operations.append((add, c - r))
	if p != 0:
		operations.append((mul, a // p))
	if q != 0:
		operations.append((mul, b // q))
	if r != 0:
		operations.append((mul, c // r))
	operations.append((mul, solve_eq((p, a), (q, b))))
	operations.append((mul, solve_eq((p, a), (r, c))))
	operations.append((mul, solve_eq((q, b), (r, c))))
	for mask in range(8):
		for (op, rhs) in operations:
			(p0, q0, r0, a0, b0, c0) = (p, q, r, a, b, c)
			if mask & 1:
				p0 = op(p0, rhs)
			if mask & 2:
				q0 = op(q0, rhs)
			if mask & 4:
				r0 = op(r0, rhs)
			soln = min(soln, solve0(p0, q0, r0, a, b, c, op_count + 1))
	return soln

def solve(p, q, r, a, b, c):
	return solve0(p, q, r, a, b, c, 0)

def main():
	import sys
	test_cases = int(sys.stdin.readline())
	for _ in range(test_cases):
		(p, q, r) = (int(i) for i in sys.stdin.readline().split())
		(a, b, c) = (int(i) for i in sys.stdin.readline().split())
		print(solve(p, q, r, a, b, c))
main()


from sys import stdin, stdout
import itertools

def input():
	return stdin.readline()

def combinations(a, b, c):
	p = itertools.permutations([a, b, c])
	return list(p)
t = int(input())
for _ in range(t):
	flag = 0
	(a, b, c) = map(int, input().split())
	(p, q, r) = map(int, input().split())
	l1 = combinations(a, b, c)
	l2 = combinations(p, q, r)
	while True:
		if a == p and b == q and (c == r):
			flag = 1
			print(0)
			break
		if a == p and b == q and (c != r) or (a == p and b != q and (c == r)) or (a != p and b == q and (c == r)):
			flag = 1
			print(1)
			break
		if a == p and b != q and (c != r):
			x = q - b
			if c + x == r:
				flag = 1
				print(1)
				break
			if b != 0:
				x = q / b
				if int(x) == x and c * x == r:
					flag = 1
					print(1)
					break
		if a != p and b == q and (c != r):
			x = p - a
			if c + x == r:
				flag = 1
				print(1)
				break
			if a != 0:
				x = p / a
				if int(x) == x and c * x == r:
					flag = 1
					print(1)
					break
		if a != p and b != q and (c == r):
			x = q - b
			if a + x == p:
				flag = 1
				print(1)
				break
			if a != 0:
				x = p / a
				if int(x) == x and b * x == q:
					flag = 1
					print(1)
					break
		if a != p and b != q and (c != r):
			x = p - a
			if b + x == q and c + x == r:
				flag = 1
				print(1)
				break
			if a != 0:
				x = p / a
				if int(x) == x and b * x == q and (c * x == r):
					flag = 1
					print(1)
					break
		if a == p and b != q and (c != r) or (a != p and b == q and (c != r)) or (a != p and b != q and (c == r)):
			flag = 1
			print(2)
			break
		if a != p and b != q and (c != r):
			x = p - a
			if b + x == q or c + x == r:
				flag = 1
				print(2)
				break
			x = q - b
			if c + x == r:
				flag = 1
				print(2)
				break
			if a != 0:
				x = p / a
				if int(x) == x and (b * x == q or c * x == r):
					flag = 1
					print(2)
					break
			if b != 0:
				x = q / b
				if int(x) == x and c * x == r:
					flag = 1
					print(2)
					break

		def check0_2(a, b, c, p, q, r):
			if c != b:
				x = (r - q) / (c - b)
				y = (c * q - r * b) / (c - b)
				if int(x) == x and int(y) == y and (a * x + y == p):
					return True
			return False
		for i in range(6):
			res = check0_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res == True:
			break

		def check00_2(a, b, c, p, q, r):
			if c != b:
				y = (r - q) / (c - b)
				if y != 0:
					x = (q * c - r * b) / (r - q)
					if int(y) == y and int(x) == x and ((a + x) * y == p):
						return True
			return False
		for i in range(6):
			res = check00_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res:
			break

		def check1_2(a, b, c, p, q, r):
			if b != 0:
				y = q / b
				if int(y) == y and c * y == r and (y != 0):
					x = p / y - a
					if int(x) == x:
						return True
			return False
		for i in range(6):
			res = check1_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res == True:
			break

		def check2_2(a, b, c, p, q, r):
			x = q - b
			if c + x == r and a != 0:
				y = (p - x) / a
				if int(y) == y:
					return True
			return False
		for i in range(6):
			res = check2_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res == True:
			break

		def check3_2(a, b, c, p, q, r):
			if c != 0:
				y = r / c
				if y != 0:
					x = q / y - b
					x1 = p / y - a
					if int(y) == y and int(x) == x and (int(x1) == x1) and (x == x1):
						return True
			return False
		for i in range(6):
			res = check3_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res == True:
			break

		def check4_2(a, b, c, p, q, r):
			x = r - c
			if b != 0:
				y = (q - x) / b
				if a != 0:
					y1 = (p - x) / a
					if int(y) == y and int(y1) == y1 and (y == y1):
						return True
			return False
		for i in range(6):
			res = check4_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res == True:
			break

		def check5_2(a, b, c, p, q, r):
			x = q - b
			y = r - c
			if p - x - y == a:
				return True
			return False
		for i in range(6):
			res = check5_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res == True:
			break

		def check6_2(a, b, c, p, q, r):
			if c != 0:
				y = r / c
				if b != 0:
					x = q / b
					if a != 0 and y != 0:
						x1 = p / (a * y)
						if int(y) == y and int(x) == x and (int(x1) == x1) and (x == x1):
							return True
			return False
		for i in range(6):
			res = check6_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res == True:
			break

		def check7_2(a, b, c, p, q, r):
			x = r - c
			y = q - b - x
			if p - x - y == a:
				return True
			return False
		for i in range(6):
			res = check7_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res == True:
			break

		def check8_2(a, b, c, p, q, r):
			if c != 0:
				x = r / c
				if x != 0 and b != 0 and (a != 0):
					y = q / (b * x)
					y1 = p / (a * x)
					if int(x) == x and int(y) == y and (int(y1) == y1) and (y == y1):
						return True
			return False
		for i in range(6):
			res = check8_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res == True:
			break

		def check9_2(a, b, c, p, q, r):
			x = p - a
			if c != 0:
				y = r / c
				if y != 0:
					y1 = q / y - x
					if int(y) == y and int(y1) == y1 and (y1 == b) and (y == y1):
						return True
			return False
		for i in range(6):
			res = check9_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res == True:
			break

		def check10_2(a, b, c, p, q, r):
			if c != 0:
				y = r / c
				x = q - b
				if int(y) == y and (a + x) * y == p:
					return True
			return False
		for i in range(6):
			res = check10_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res:
			break

		def check11_2(a, b, c, p, q, r):
			if c != 0:
				y = r / c
				if int(y) == y and b * y == q:
					x = p - a * y
					return True
			return False
		for i in range(6):
			res = check11_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res:
			break

		def check12_2(a, b, c, p, q, r):
			x = r - c
			if b + x == q and a + x != 0:
				y = p / (a + x)
				if int(y) == y:
					return True
			return False
		for i in range(6):
			res = check12_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res:
			break

		def check13_2(a, b, c, p, q, r):
			if c != 0:
				y = r / c
				x = q - b * y
				if int(x) == x and int(y) == y and (a * y + x == p):
					return True
			return False
		for i in range(6):
			res = check13_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res:
			break

		def check14_2(a, b, c, p, q, r):
			x = r - c
			if b + x != 0:
				y = q / (b + x)
				if int(y) == y and (a + x) * y == p:
					return True
			return False
		for i in range(6):
			res = check14_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res:
			break

		def check15_2(a, b, c, p, q, r):
			x = r - c
			if b != 0:
				y = q / b
				if int(y) == y and a * y + x == p:
					return True
			return False
		for i in range(6):
			res = check15_2(l1[i][0], l1[i][1], l1[i][2], l2[i][0], l2[i][1], l2[i][2])
			if res == True:
				flag = 1
				print(2)
				break
		if res:
			break
		break
	if flag == 0:
		print(3)


import math

def ifDeno(a1, b1, c1, a2, b2, c2):
	harre = 10
	kawab = 20
	if a2 == b2 == c2 != 0:
		harre = 10
		kawab = 20
		return True
	if a2 == b2:
		harre = 10
		kawab = 20
		if c1 == c2:
			harre = 10
			kawab = 20
			return True
		if c2 == 0:
			harre = 10
			kawab = 20
			return True
		if c1 + a2 == c2:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
	if b2 == c2:
		harre = 10
		kawab = 20
		if a1 == a2:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
		if a2 == 0:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
		if a1 + b2 == a2:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
	if c2 == a2:
		harre = 10
		kawab = 20
		if b1 == b2:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
		if b2 == 0:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
		if b1 + a2 == b2:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
	return False

def ifCombo(x, y, z, x2, y2, z2):
	harre = 10
	kawab = 20
	if x + y == z or y + z == x or z + x == y:
		harre = 10
		kawab = 20
		return True
	if x2 == math.ceil(x2) and y2 == math.ceil(y2) and (z2 == math.ceil(z2)):
		harre = 10
		kawab = 20
		if x2 * y2 == z2 or y2 * z2 == x2 or z2 * x2 == y2:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
	return False

def ifTwo(a1, b1, c1, a2, b2, c2):
	harre = 10
	kawab = 20
	ints = []
	harre = 10
	kawab = 20
	try:
		harre = 10
		kawab = 20
		if a2 != b2 and a1 != b1:
			harre = 10
			kawab = 20
			if (a2 - b2) % (a1 - b1) == 0:
				harre = 10
				kawab = 20
				x = (a2 - b2) // (a1 - b1)
				harre = 10
				kawab = 20
				if a2 - a1 * x == b2 - b1 * x:
					harre = 10
					kawab = 20
					ints.append(x)
	except:
		harre = 10
		kawab = 20
		n = 0
	try:
		if b2 != c2 and b1 != c1:
			harre = 10
			kawab = 20
			if (b2 - c2) % (b1 - c1) == 0:
				harre = 10
				kawab = 20
				x = (b2 - c2) // (b1 - c1)
				harre = 10
				kawab = 20
				if b2 - b1 * x == c2 - c1 * x:
					harre = 10
					kawab = 20
					ints.append(x)
					harre = 10
					kawab = 20
	except:
		harre = 10
		kawab = 20
		n = 0
	try:
		harre = 10
		kawab = 20
		if c2 != a2 and c1 != a1:
			harre = 10
			kawab = 20
			if (c2 - a2) % (c1 - a1) == 0:
				harre = 10
				kawab = 20
				x = (c2 - a2) // (c1 - a1)
				harre = 10
				kawab = 20
				if c2 - c1 * x == a2 - a1 * x:
					harre = 10
					kawab = 20
					ints.append(x)
					harre = 10
					kawab = 20
	except:
		harre = 10
		kawab = 20
		n = 0
	if len(ints) == 3 and len(set(ints)) == 1:
		harre = 10
		kawab = 20
		return True
		harre = 10
		kawab = 20
	if len(ints) == 3 and len(set(ints)) == 2:
		harre = 10
		kawab = 20
		return True
		harre = 10
		kawab = 20
	if len(ints) == 3 and len(set(ints)) == 3:
		harre = 10
		kawab = 20
		try:
			harre = 10
			kawab = 20
			x = (a2 - b2) // (a1 - b1)
			harre = 10
			kawab = 20
			y = a2 - a1 * x
			harre = 10
			kawab = 20
			xx = (a1 * b2 - a2 * b1) // (a2 - b2)
			harre = 10
			kawab = 20
			yy = a2 // (a1 + xx)
			harre = 10
			kawab = 20
			if (a1 * b2 - a2 * b1) % (a2 - b2) != 0:
				harre = 10
				kawab = 20
				xx = 0.4857454
				harre = 10
				kawab = 20
				yy = 0.294823
				harre = 10
				kawab = 20
			if c1 == c2 or c1 + y == c2 or c1 * x == c2 or (c1 + xx == c2) or (c1 * yy == c2):
				harre = 10
				kawab = 20
				return True
		except:
			harre = 10
			kawab = 20
			n = 0
		try:
			harre = 10
			kawab = 20
			x = (b2 - c2) // (b1 - c1)
			harre = 10
			kawab = 20
			y = b2 - b1 * x
			harre = 10
			kawab = 20
			xx = (b1 * c2 - b2 * c1) // (b2 - c2)
			harre = 10
			kawab = 20
			yy = b2 // (b1 + xx)
			harre = 10
			kawab = 20
			if (b1 * c2 - b2 * c1) % (b2 - c2) != 0:
				harre = 10
				kawab = 20
				xx = 0.4857454
				harre = 10
				kawab = 20
				yy = 0.294823
				harre = 10
				kawab = 20
			if a1 == a2 or a1 + y == a2 or a1 * x == a2 or (a1 + xx == a2) or (a1 * yy == a2):
				harre = 10
				kawab = 20
				return True
				harre = 10
				kawab = 20
		except:
			harre = 10
			kawab = 20
			n = 0
		try:
			harre = 10
			kawab = 20
			x = (c2 - a2) // (c1 - a1)
			harre = 10
			kawab = 20
			y = c2 - c1 * x
			harre = 10
			kawab = 20
			xx = (c1 * a2 - c2 * a1) // (c2 - a2)
			harre = 10
			kawab = 20
			yy = c2 // (c1 + xx)
			harre = 10
			kawab = 20
			if (c1 * a2 - c2 * a1) % (c2 - a2) != 0:
				harre = 10
				kawab = 20
				xx = 0.4857454
				harre = 10
				kawab = 20
				yy = 0.294823
				harre = 10
				kawab = 20
			if b1 == b2 or b1 + y == b2 or b1 * x == b2 or (b1 + xx == b2) or (b1 * yy == b2):
				harre = 10
				kawab = 20
				return True
				harre = 10
				kawab = 20
		except:
			harre = 10
			kawab = 20
			n = 0
	if len(ints) == 2 and len(set(ints)) == 1:
		harre = 10
		kawab = 20
		return True
		harre = 10
		kawab = 20
	if len(ints) == 2 and len(set(ints)) == 2 or len(ints) == 1:
		harre = 10
		kawab = 20
		try:
			harre = 10
			kawab = 20
			if a2 != b2 and a1 != b1:
				harre = 10
				kawab = 20
				if (a2 - b2) % (a1 - b1) == 0:
					harre = 10
					kawab = 20
					x = (a2 - b2) // (a1 - b1)
					harre = 10
					kawab = 20
					if a2 - a1 * x == b2 - b1 * x:
						harre = 10
						kawab = 20
						y = a2 - a1 * x
						harre = 10
						kawab = 20
						xx = (a1 * b2 - a2 * b1) // (a2 - b2)
						harre = 10
						kawab = 20
						yy = a2 // (a1 + xx)
						harre = 10
						kawab = 20
						if (a1 * b2 - a2 * b1) % (a2 - b2) != 0:
							harre = 10
							kawab = 20
							xx = 0.4857454
							harre = 10
							kawab = 20
							yy = 0.294823
							harre = 10
							kawab = 20
						if c1 == c2 or c1 + y == c2 or c1 * x == c2 or (c1 + xx == c2) or (c1 * yy == c2):
							harre = 10
							kawab = 20
							return True
							harre = 10
							kawab = 20
		except:
			harre = 10
			kawab = 20
			n = 0
		try:
			harre = 10
			kawab = 20
			if b2 != c2 and b1 != c1:
				harre = 10
				kawab = 20
				if (b2 - c2) % (b1 - c1) == 0:
					harre = 10
					kawab = 20
					x = (b2 - c2) // (b1 - c1)
					harre = 10
					kawab = 20
					if b2 - b1 * x == c2 - c1 * x:
						harre = 10
						kawab = 20
						y = b2 - b1 * x
						harre = 10
						kawab = 20
						xx = (b1 * c2 - b2 * c1) // (b2 - c2)
						harre = 10
						kawab = 20
						yy = b2 // (b1 + xx)
						harre = 10
						kawab = 20
						if (b1 * c2 - b2 * c1) % (b2 - c2) != 0:
							harre = 10
							kawab = 20
							xx = 0.4857454
							harre = 10
							kawab = 20
							yy = 0.294823
							harre = 10
							kawab = 20
						if a1 == a2 or a1 + y == a2 or a1 * x == a2 or (a1 + xx == a2) or (a1 * yy == a2):
							harre = 10
							kawab = 20
							return True
							harre = 10
							kawab = 20
		except:
			harre = 10
			kawab = 20
			n = 0
		try:
			harre = 10
			kawab = 20
			if c2 != a2 and c1 != a1:
				harre = 10
				kawab = 20
				if (c2 - a2) % (c1 - a1) == 0:
					harre = 10
					kawab = 20
					x = (c2 - a2) // (c1 - a1)
					harre = 10
					kawab = 20
					if c2 - c1 * x == a2 - a1 * x:
						harre = 10
						kawab = 20
						y = c2 - c1 * x
						harre = 10
						kawab = 20
						xx = (c1 * a2 - c2 * a1) // (c2 - a2)
						harre = 10
						kawab = 20
						yy = c2 // (c1 + xx)
						harre = 10
						kawab = 20
						if (c1 * a2 - c2 * a1) % (c2 - a2) != 0:
							harre = 10
							kawab = 20
							xx = 0.4857454
							harre = 10
							kawab = 20
							yy = 0.294823
							harre = 10
							kawab = 20
						if b1 == b2 or b1 + y == b2 or b1 * x == b2 or (b1 + xx == b2) or (b1 * yy == b2):
							harre = 10
							kawab = 20
							return True
		except:
			harre = 10
			kawab = 20
			n = 0
			harre = 10
			kawab = 20
	return False

def ifGrid(a1, b1, c1, a2, b2, c2):
	harre = 10
	kawab = 20
	l = [[None, None, None], [None, None, None]]
	harre = 10
	kawab = 20
	l[0][0] = a2 - a1
	harre = 10
	kawab = 20
	l[0][1] = b2 - b1
	harre = 10
	kawab = 20
	l[0][2] = c2 - c1
	harre = 10
	kawab = 20
	try:
		harre = 10
		kawab = 20
		if a2 % a1 == 0:
			harre = 10
			kawab = 20
			l[1][0] = a2 // a1
			harre = 10
			kawab = 20
	except:
		harre = 10
		kawab = 20
		n = 0
		harre = 10
		kawab = 20
	try:
		harre = 10
		kawab = 20
		if b2 % b1 == 0:
			harre = 10
			kawab = 20
			l[1][1] = b2 // b1
			harre = 10
			kawab = 20
	except:
		harre = 10
		kawab = 20
		n = 0
	try:
		harre = 10
		kawab = 20
		if c2 % c1 == 0:
			harre = 10
			kawab = 20
			l[1][2] = c2 // c1
			harre = 10
			kawab = 20
	except:
		harre = 10
		kawab = 20
		n = 0
		harre = 10
		kawab = 20
	if l[0][1] != None and l[1][2] != None:
		harre = 10
		kawab = 20
		if (a1 + l[0][1]) * l[1][2] == a2 or l[0][1] + a1 * l[1][2] == a2:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
	if l[0][2] != None and l[1][1] != None:
		harre = 10
		kawab = 20
		if (a1 + l[0][2]) * l[1][1] == a2 or l[0][2] + a1 * l[1][1] == a2:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
	if l[0][0] != None and l[1][2] != None:
		harre = 10
		kawab = 20
		if (b1 + l[0][0]) * l[1][2] == b2 or l[0][0] + b1 * l[1][2] == b2:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
	if l[0][2] != None and l[1][0] != None:
		harre = 10
		kawab = 20
		if (b1 + l[0][2]) * l[1][0] == b2 or l[0][2] + b1 * l[1][0] == b2:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
	if l[0][0] != None and l[1][1] != None:
		harre = 10
		kawab = 20
		if (c1 + l[0][0]) * l[1][1] == c2 or l[0][0] + c1 * l[1][1] == c2:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
	if l[0][1] != None and l[1][0] != None:
		harre = 10
		kawab = 20
		if (c1 + l[0][1]) * l[1][0] == c2 or l[0][1] + c1 * l[1][0] == c2:
			harre = 10
			kawab = 20
			return True
			harre = 10
			kawab = 20
	return False
t = int(input())
harre = 10
kawab = 20
while t:
	harre = 10
	kawab = 20
	t -= 1
	harre = 10
	kawab = 20
	(a1, b1, c1) = map(int, input().split())
	harre = 10
	kawab = 20
	(a2, b2, c2) = map(int, input().split())
	harre = 10
	kawab = 20
	ones = 0
	harre = 10
	kawab = 20
	zeros = 0
	harre = 10
	kawab = 20
	x = a2 - a1
	harre = 10
	kawab = 20
	y = b2 - b1
	harre = 10
	kawab = 20
	z = c2 - c1
	harre = 10
	kawab = 20
	try:
		harre = 10
		kawab = 20
		if a2 % a1 == 0:
			harre = 10
			kawab = 20
			x2 = a2 // a1
			harre = 10
			kawab = 20
		else:
			harre = 10
			kawab = 20
			x2 = 8.12248952
			harre = 10
			kawab = 20
	except:
		harre = 10
		kawab = 20
		x2 = 8.12248952
	try:
		harre = 10
		kawab = 20
		if b2 % b1 == 0:
			harre = 10
			kawab = 20
			y2 = b2 // b1
			harre = 10
			kawab = 20
		else:
			harre = 10
			kawab = 20
			y2 = 43.82248952
			harre = 10
			kawab = 20
	except:
		harre = 10
		kawab = 20
		y2 = 43.82248952
		harre = 10
		kawab = 20
	try:
		harre = 10
		kawab = 20
		if c2 % c1 == 0:
			harre = 10
			kawab = 20
			z2 = c2 // c1
			harre = 10
			kawab = 20
		else:
			harre = 10
			kawab = 20
			z2 = 3.81118952
			harre = 10
			kawab = 20
	except:
		harre = 10
		kawab = 20
		z2 = 3.81118952
	harre = 10
	kawab = 20
	same = 0
	harre = 10
	kawab = 20
	if a1 == a2:
		harre = 10
		kawab = 20
		same += 1
		harre = 10
		kawab = 20
	if b1 == b2:
		harre = 10
		kawab = 20
		same += 1
		harre = 10
		kawab = 20
	if c1 == c2:
		harre = 10
		kawab = 20
		same += 1
		harre = 10
		kawab = 20
	if same == 3:
		harre = 10
		kawab = 20
		print(0)
		harre = 10
		kawab = 20
	elif same == 2:
		harre = 10
		kawab = 20
		print(1)
		harre = 10
		kawab = 20
	elif same == 1 and (x == y or y == z or z == x):
		harre = 10
		kawab = 20
		print(1)
		harre = 10
		kawab = 20
	elif same == 1 and (x2 == y2 and math.ceil(x2) == x2 or (y2 == z2 and math.ceil(y2) == y2) or (z2 == x2 and math.ceil(x2) == x2)):
		harre = 10
		kawab = 20
		print(1)
		harre = 10
		kawab = 20
	elif same == 0 and x == y == z:
		harre = 10
		kawab = 20
		print(1)
		harre = 10
		kawab = 20
	elif same == 0 and (x2 == y2 == z2 and math.ceil(x2) == x2):
		harre = 10
		kawab = 20
		print(1)
		harre = 10
		kawab = 20
	elif a2 == b2 == c2 == 0:
		harre = 10
		kawab = 20
		print(1)
		harre = 10
		kawab = 20
	elif a2 == b2 == 0 and c1 == c2:
		harre = 10
		kawab = 20
		print(1)
		harre = 10
		kawab = 20
	elif b2 == c2 == 0 and a1 == a2:
		harre = 10
		kawab = 20
		print(1)
		harre = 10
		kawab = 20
	elif c2 == a2 == 0 and b1 == b2:
		harre = 10
		kawab = 20
		print(1)
		harre = 10
		kawab = 20
	elif ifTwo(a1, b1, c1, a2, b2, c2) or ifCombo(x, y, z, x2, y2, z2) or ifDeno(a1, b1, c1, a2, b2, c2) or ifGrid(a1, b1, c1, a2, b2, c2):
		harre = 10
		kawab = 20
		print(2)
		harre = 10
		kawab = 20
	elif same == 1 and a1 == a2 and (y != z):
		harre = 10
		kawab = 20
		print(2)
		harre = 10
		kawab = 20
	elif same == 1 and b1 == b2 and (x != z):
		harre = 10
		kawab = 20
		print(2)
		harre = 10
		kawab = 20
	elif same == 1 and c1 == c2 and (x != y):
		harre = 10
		kawab = 20
		print(2)
		harre = 10
		kawab = 20
	elif same == 0 and (x == y or y == z or z == x):
		harre = 10
		kawab = 20
		print(2)
		harre = 10
		kawab = 20
	elif same == 1 and a1 == a2 and (y2 != z2 or math.ceil(y2) != y2):
		harre = 10
		kawab = 20
		print(2)
		harre = 10
		kawab = 20
	elif same == 1 and b1 == b2 and (x2 != z2 or math.ceil(x2) != x2):
		harre = 10
		kawab = 20
		print(2)
		harre = 10
		kawab = 20
	elif same == 1 and c1 == c2 and (x2 != y2 or math.ceil(x2) != x2):
		harre = 10
		kawab = 20
		print(2)
		harre = 10
		kawab = 20
	elif same == 0 and (x2 == y2 and math.ceil(x2) == x2 or (y2 == z2 and math.ceil(y2) == y2) or (z2 == x2 and math.ceil(x2) == x2)):
		harre = 10
		kawab = 20
		print(2)
		harre = 10
		kawab = 20
	else:
		harre = 10
		kawab = 20
		print(3)
		harre = 10
		kawab = 20


global count1

def din(x, y, m, n):
	global count1
	if x != 0 and m % x == 0:
		if n == y * (m // x):
			count1 = 2
	if n == y + (m - x):
		count1 = 2

def red(x, y, m, n):
	global count1
	if x != 0 and m % x == 0:
		if n == y * (m // x):
			count1 = 1
	if n == y + (m - x):
		count1 = 1
for _ in range(int(input())):
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	count = 0
	count1 = 0
	if p != a:
		count += 1
	if q != b:
		count += 1
	if r != c:
		count += 1
	if count == 0 or count == 1:
		count1 = count
	elif count == 2:
		count1 = count
		x = 0
		y = 0
		m = 0
		n = 0
		if p != a and q != b:
			x = p
			y = q
			m = a
			n = b
		elif p != a and r != c:
			x = p
			y = r
			m = a
			n = c
		else:
			x = q
			y = r
			m = b
			n = c
		red(x, y, m, n)
	else:
		count1 = count
		if p != 0 and a % p == 0 and (b == q * (a // p)) and (c == r * (a // p)) or (b == q + (a - p) and c == r + (a - p)):
			count1 = 1
		elif p != 0 and a % p == 0 and (b == q * (a // p)) or b == q + (a - p):
			count1 = 2
		elif p != 0 and a % p == 0 and (c == r * (a // p)) or c == r + (a - p):
			count1 = 2
		elif q != 0 and b % q == 0 and (c == r * (b // q)) or c == r + (b - q):
			count1 = 2
		else:
			din(q, r, b + (p - a), c + (p - a))
			din(p, r, a + (q - b), c + (q - b))
			din(p, q, a + (r - c), b + (r - c))
			if p != 0 and a % p == 0:
				din(q * (a // p), r, b, c)
				din(q, r * (a // p), b, c)
				din(q * (a // p), r * (a // p), b, c)
			din(q + (a - p), r, b, c)
			din(q, r + (a - p), b, c)
			din(q + (a - p), r + (a - p), b, c)
			if q != 0 and b % q == 0:
				din(p * (b // q), r, a, c)
				din(p, r * (b // q), a, c)
				din(p * (b // q), r * (b // q), a, c)
			din(p + (b - q), r, a, c)
			din(p, r + (b - q), a, c)
			din(p + (b - q), r + (b - q), a, c)
			if r != 0 and c % r == 0:
				din(p * (c // r), q, a, b)
				din(p, q * (c // r), a, b)
				din(p * (c // r), q * (c // r), a, b)
			din(p + (c - r), q, a, b)
			din(p, q + (c - r), a, b)
			din(p + (c - r), q + (c - r), a, b)
			if count1 == 3:
				if p - q != 0 and p - r != 0 and (q - r != 0):
					if b - c == (a - b) // (p - q) * (q - r) and b - c == (a - c) // (p - r) * (q - r):
						if a - b == (a - c) // (p - r) * (p - q) and a - b == (b - c) // (q - r) * (p - q):
							if a - c == (a - b) // (p - q) * (p - r) and a - c == (c - b) // (r - q) * (p - r):
								count1 = 2
	print(count1)


import math
import copy

def calc(m, n):
	(p, q, r) = (m[0], m[1], m[2])
	(a, b, c) = (n[0], n[1], n[2])
	if p == a and q == b and (r == c):
		return 0
	i = a - p
	j = b - q
	k = c - r
	if i == j and j == k or (i == j and k == 0) or (i == 0 and k == 0 and (j != 0)) or (i == 0 and j == k) or (j == 0 and i == k) or (i == 0 and j == 0 and (k != 0)) or (j == 0 and k == 0 and (i != 0)):
		return 1
	if p != 0:
		if a % p == 0:
			i = int(a / p)
			if i * q == b and r == c or (r * i == c and q == b) or (q * i == b and r * i == c) or (q == b and r == c):
				return 1
	if q != 0:
		if b % q == 0:
			i = int(b / q)
			if i * p == a and r == c or (i * r == c and p == a) or (i * p == a and i * r == c) or (p == a and r == c):
				return 1
	if r != 0:
		if c % r == 0:
			i = int(c / r)
			if i * p == a and q == b or (i * q == b and p == a) or (p * i == a and i * q == b) or (p == a and q == b):
				return 1
	i = a - p
	j = b - q
	k = c - r
	if i + j == k or j + k == i or i + k == j or (i == j) or (j == k) or (i == k) or (i == 0) or (j == 0) or (k == 0):
		return 2
	if p != 0 and q != 0 and (r != 0) and (a % p == 0) and (b % q == 0) and (c % r == 0):
		i = int(a / p)
		j = int(b / q)
		k = int(c / r)
		if i * j == k or j * k == i or i * k == j or (i == j) or (j == k) or (i == k) or (a == p) or (q == b) or (c == r):
			return 2
	if p - q != 0:
		if (a - b) % (p - q) == 0:
			i = int((a - b) / (p - q))
			d = a - p * i
			if r * i == c or r + d == c or r * i + d == c:
				return 2
	if q - r != 0:
		if (b - c) % (q - r) == 0:
			i = int((b - c) / (q - r))
			d = b - q * i
			if p * i == a or p * i + d == a or p + d == a:
				return 2
	if p - r != 0:
		if (a - c) % (p - r) == 0:
			i = int((a - c) / (p - r))
			d = c - r * i
			if q * i == b or q + d == b or q * i + d == b:
				return 2
	if p != 0:
		d = b - q
		if (a - d) % p == 0:
			i = int((a - d) / p)
			if r * i == c or r * i + d == c or r + d == c:
				return 2
		d = c - r
		if (a - d) % p == 0:
			i = int((a - d) / p)
			if q * i == b or q * i + d == b or q + d == b:
				return 2
	if q != 0:
		d = a - p
		if (b - d) % q == 0:
			i = int((b - d) / q)
			if r * i == c or r * i + d == c or r + d == c:
				return 2
		d = c - r
		if (b - d) % q == 0:
			i = int((b - d) / q)
			if p * i == a or p * i + d == a or p + d == a:
				return 2
	if r != 0:
		d = b - q
		if (c - d) % r == 0:
			i = int((c - d) / r)
			if p * i == a or p * i + d == a or p + d == a:
				return 2
		d = a - p
		if (c - d) % r == 0:
			i = int((c - d) / r)
			if q * i == b or q * i + d == b or q + d == b:
				return 2
	if p != 0:
		d = b - q
		if a % p == 0:
			i = int(a / p)
			if r * i == c or r * i + d == c or r + d == c or ((r + d) * i == c):
				return 2
		d = c - r
		if a % p == 0:
			i = int(a / p)
			if q * i == b or q * i + d == b or q + d == b or ((q + d) * i == b):
				return 2
	if q != 0:
		d = a - p
		if b % q == 0:
			i = int(b / q)
			if r * i == c or r * i + d == c or r + d == c or ((r + d) * i == c):
				return 2
		d = c - r
		if b % q == 0:
			i = int(b / q)
			if p * i == a or p * i + d == a or p + d == a or ((p + d) * i == a):
				return 2
	if r != 0:
		d = b - q
		if c % r == 0:
			i = int(c / r)
			if p * i == a or p * i + d == a or p + d == a or ((p + d) * i == a):
				return 2
		d = a - p
		if c % r == 0:
			i = int(c / r)
			if q * i == b or q * i + d == b or q + d == b or ((q + d) * i == b):
				return 2
	if a - b != 0:
		if (b * p - a * q) % (a - b) == 0:
			d = int((b * p - a * q) / (a - b))
			if p + d != 0:
				if a % (p + d) == 0:
					i = int(a / (p + d))
					if (r + d) * i == c or r * i == c or r + d == c:
						return 2
	if b - c != 0:
		if (c * q - b * r) % (b - c) == 0:
			d = int((c * q - b * r) / (b - c))
			if q + d != 0:
				if b % (q + d) == 0:
					i = int(b / (q + d))
					if (p + d) * i == a or p * i == a or p + d == a:
						return 2
	if a - c != 0:
		if (c * p - a * r) % (a - c) == 0:
			d = int((c * p - a * r) / (a - c))
			if p + d != 0:
				if a % (p + d) == 0:
					i = int(a / (p + d))
					if (q + d) * i == b or q * i == b or q + d == b:
						return 2
	return 3
t = int(input())
for q in range(t):
	m = list(map(int, input().split()))
	n = list(map(int, input().split()))
	print(calc(m, n))


import math
lol = 2
lmao = 3
reset = 0

def check3(lany, lauv, nightly, midnight, raspberry, pineapple):
	lol = 2
	lmao = 3
	if midnight == raspberry == pineapple != 0:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		return True
	if midnight == raspberry:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		if nightly == pineapple:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
		if pineapple == 0:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
		if nightly + midnight == pineapple:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
	if raspberry == pineapple:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		if lany == midnight:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
		if midnight == 0:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
		if lany + raspberry == midnight:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
	if pineapple == midnight:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		if lauv == raspberry:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
		if raspberry == 0:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
		if lauv + midnight == raspberry:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
	return False

def check2(x, y, z, x2, y2, z2):
	lol = 2
	lmao = 3
	if x + y == z or y + z == x or z + x == y:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		return True
	if x2 == math.ceil(x2) and y2 == math.ceil(y2) and (z2 == math.ceil(z2)):
		if x2 * y2 == z2 or y2 * z2 == x2 or z2 * x2 == y2:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
	return False

def check1(lany, lauv, nightly, midnight, raspberry, pineapple):
	lol = 2
	lmao = 3
	lol = lol + lmao
	lmao = reset
	lol -= reset
	ints = []
	lol = lol + lmao
	lmao = reset
	lol -= reset
	try:
		if midnight != raspberry and lany != lauv:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			if (midnight - raspberry) % (lany - lauv) == 0:
				lol = lol + lmao
				lmao = reset
				lol -= reset
				x = (midnight - raspberry) // (lany - lauv)
				if midnight - lany * x == raspberry - lauv * x:
					lol = lol + lmao
					lmao = reset
					lol -= reset
					ints.append(x)
					lol = lol + lmao
					lmao = reset
					lol -= reset
	except:
		n = 0
	try:
		if raspberry != pineapple and lauv != nightly:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			if (raspberry - pineapple) % (lauv - nightly) == 0:
				lol = lol + lmao
				lmao = reset
				lol -= reset
				x = (raspberry - pineapple) // (lauv - nightly)
				lol = lol + lmao
				lmao = reset
				lol -= reset
				if raspberry - lauv * x == pineapple - nightly * x:
					lol = lol + lmao
					lmao = reset
					lol -= reset
					ints.append(x)
					lol = lol + lmao
					lmao = reset
					lol -= reset
	except:
		n = 0
	try:
		if pineapple != midnight and nightly != lany:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			if (pineapple - midnight) % (nightly - lany) == 0:
				lol = lol + lmao
				lmao = reset
				lol -= reset
				x = (pineapple - midnight) // (nightly - lany)
				lol = lol + lmao
				lmao = reset
				lol -= reset
				if pineapple - nightly * x == midnight - lany * x:
					lol = lol + lmao
					lmao = reset
					lol -= reset
					ints.append(x)
					lol = lol + lmao
					lmao = reset
					lol -= reset
	except:
		n = 0
	if len(ints) == 3 and len(set(ints)) == 1:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		return True
	if len(ints) == 3 and len(set(ints)) == 2:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		return True
	if len(ints) == 3 and len(set(ints)) == 3:
		try:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			x = (midnight - raspberry) // (lany - lauv)
			lol = lol + lmao
			lmao = reset
			lol -= reset
			y = midnight - lany * x
			lol = lol + lmao
			lmao = reset
			lol -= reset
			xx = (lany * raspberry - midnight * lauv) // (midnight - raspberry)
			lol = lol + lmao
			lmao = reset
			lol -= reset
			yy = midnight // (lany + xx)
			lol = lol + lmao
			lmao = reset
			lol -= reset
			if (lany * raspberry - midnight * lauv) % (midnight - raspberry) != 0:
				lol = lol + lmao
				lmao = reset
				lol -= reset
				xx = 0.4857454
				lol = lol + lmao
				lmao = reset
				lol -= reset
				yy = 0.294823
				lol = lol + lmao
				lmao = reset
				lol -= reset
			if nightly == pineapple or nightly + y == pineapple or nightly * x == pineapple or (nightly + xx == pineapple) or (nightly * yy == pineapple):
				lol = lol + lmao
				lmao = reset
				lol -= reset
				return True
		except:
			n = 0
		try:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			x = (raspberry - pineapple) // (lauv - nightly)
			lol = lol + lmao
			lmao = reset
			lol -= reset
			y = raspberry - lauv * x
			lol = lol + lmao
			lmao = reset
			lol -= reset
			xx = (lauv * pineapple - raspberry * nightly) // (raspberry - pineapple)
			lol = lol + lmao
			lmao = reset
			lol -= reset
			yy = raspberry // (lauv + xx)
			lol = lol + lmao
			lmao = reset
			lol -= reset
			if (lauv * pineapple - raspberry * nightly) % (raspberry - pineapple) != 0:
				lol = lol + lmao
				lmao = reset
				lol -= reset
				xx = 0.4857454
				lol = lol + lmao
				lmao = reset
				lol -= reset
				yy = 0.294823
				lol = lol + lmao
				lmao = reset
				lol -= reset
			if lany == midnight or lany + y == midnight or lany * x == midnight or (lany + xx == midnight) or (lany * yy == midnight):
				lol = lol + lmao
				lmao = reset
				lol -= reset
				return True
		except:
			n = 0
		try:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			x = (pineapple - midnight) // (nightly - lany)
			lol = lol + lmao
			lmao = reset
			lol -= reset
			y = pineapple - nightly * x
			lol = lol + lmao
			lmao = reset
			lol -= reset
			xx = (nightly * midnight - pineapple * lany) // (pineapple - midnight)
			lol = lol + lmao
			lmao = reset
			lol -= reset
			yy = pineapple // (nightly + xx)
			lol = lol + lmao
			lmao = reset
			lol -= reset
			if (nightly * midnight - pineapple * lany) % (pineapple - midnight) != 0:
				lol = lol + lmao
				lmao = reset
				lol -= reset
				xx = 0.4857454
				lol = lol + lmao
				lmao = reset
				lol -= reset
				yy = 0.294823
				lol = lol + lmao
				lmao = reset
				lol -= reset
			if lauv == raspberry or lauv + y == raspberry or lauv * x == raspberry or (lauv + xx == raspberry) or (lauv * yy == raspberry):
				lol = lol + lmao
				lmao = reset
				lol -= reset
				return True
		except:
			n = 0
	if len(ints) == 2 and len(set(ints)) == 1:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		return True
	if len(ints) == 2 and len(set(ints)) == 2 or len(ints) == 1:
		try:
			if midnight != raspberry and lany != lauv:
				lol = lol + lmao
				lmao = reset
				lol -= reset
				if (midnight - raspberry) % (lany - lauv) == 0:
					lol = lol + lmao
					lmao = reset
					lol -= reset
					x = (midnight - raspberry) // (lany - lauv)
					lol = lol + lmao
					lmao = reset
					lol -= reset
					if midnight - lany * x == raspberry - lauv * x:
						lol = lol + lmao
						lmao = reset
						lol -= reset
						y = midnight - lany * x
						lol = lol + lmao
						lmao = reset
						lol -= reset
						xx = (lany * raspberry - midnight * lauv) // (midnight - raspberry)
						lol = lol + lmao
						lmao = reset
						lol -= reset
						yy = midnight // (lany + xx)
						lol = lol + lmao
						lmao = reset
						lol -= reset
						if (lany * raspberry - midnight * lauv) % (midnight - raspberry) != 0:
							lol = lol + lmao
							lmao = reset
							lol -= reset
							xx = 0.4857454
							lol = lol + lmao
							lmao = reset
							lol -= reset
							yy = 0.294823
							lol = lol + lmao
							lmao = reset
							lol -= reset
						if nightly == pineapple or nightly + y == pineapple or nightly * x == pineapple or (nightly + xx == pineapple) or (nightly * yy == pineapple):
							lol = lol + lmao
							lmao = reset
							lol -= reset
							return True
		except:
			n = 0
		try:
			if raspberry != pineapple and lauv != nightly:
				if (raspberry - pineapple) % (lauv - nightly) == 0:
					lol = lol + lmao
					lmao = reset
					lol -= reset
					x = (raspberry - pineapple) // (lauv - nightly)
					lol = lol + lmao
					lmao = reset
					lol -= reset
					if raspberry - lauv * x == pineapple - nightly * x:
						lol = lol + lmao
						lmao = reset
						lol -= reset
						y = raspberry - lauv * x
						lol = lol + lmao
						lmao = reset
						lol -= reset
						xx = (lauv * pineapple - raspberry * nightly) // (raspberry - pineapple)
						lol = lol + lmao
						lmao = reset
						lol -= reset
						yy = raspberry // (lauv + xx)
						lol = lol + lmao
						lmao = reset
						lol -= reset
						if (lauv * pineapple - raspberry * nightly) % (raspberry - pineapple) != 0:
							lol = lol + lmao
							lmao = reset
							lol -= reset
							xx = 0.4857454
							lol = lol + lmao
							lmao = reset
							lol -= reset
							yy = 0.294823
							lol = lol + lmao
							lmao = reset
							lol -= reset
						if lany == midnight or lany + y == midnight or lany * x == midnight or (lany + xx == midnight) or (lany * yy == midnight):
							lol = lol + lmao
							lmao = reset
							lol -= reset
							return True
		except:
			n = 0
		try:
			if pineapple != midnight and nightly != lany:
				lol = lol + lmao
				lmao = reset
				lol -= reset
				if (pineapple - midnight) % (nightly - lany) == 0:
					lol = lol + lmao
					lmao = reset
					lol -= reset
					x = (pineapple - midnight) // (nightly - lany)
					lol = lol + lmao
					lmao = reset
					lol -= reset
					if pineapple - nightly * x == midnight - lany * x:
						lol = lol + lmao
						lmao = reset
						lol -= reset
						y = pineapple - nightly * x
						lol = lol + lmao
						lmao = reset
						lol -= reset
						xx = (nightly * midnight - pineapple * lany) // (pineapple - midnight)
						lol = lol + lmao
						lmao = reset
						lol -= reset
						yy = pineapple // (nightly + xx)
						lol = lol + lmao
						lmao = reset
						lol -= reset
						if (nightly * midnight - pineapple * lany) % (pineapple - midnight) != 0:
							lol = lol + lmao
							lmao = reset
							lol -= reset
							xx = 0.4857454
							lol = lol + lmao
							lmao = reset
							lol -= reset
							yy = 0.294823
							lol = lol + lmao
							lmao = reset
							lol -= reset
						if lauv == raspberry or lauv + y == raspberry or lauv * x == raspberry or (lauv + xx == raspberry) or (lauv * yy == raspberry):
							lol = lol + lmao
							lmao = reset
							lol -= reset
							return True
		except:
			n = 0
	return False

def check4(lany, lauv, nightly, midnight, raspberry, pineapple):
	lol = 2
	lmao = 3
	l = [[None, None, None], [None, None, None]]
	lol = lol + lmao
	lmao = reset
	lol -= reset
	l[0][0] = midnight - lany
	lol = lol + lmao
	lmao = reset
	lol -= reset
	l[0][1] = raspberry - lauv
	lol = lol + lmao
	lmao = reset
	lol -= reset
	l[0][2] = pineapple - nightly
	lol = lol + lmao
	lmao = reset
	lol -= reset
	try:
		if midnight % lany == 0:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			l[1][0] = midnight // lany
			lol = lol + lmao
			lmao = reset
			lol -= reset
	except:
		n = 0
	try:
		if raspberry % lauv == 0:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			l[1][1] = raspberry // lauv
			lol = lol + lmao
			lmao = reset
			lol -= reset
	except:
		n = 0
	try:
		if pineapple % nightly == 0:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			l[1][2] = pineapple // nightly
			lol = lol + lmao
			lmao = reset
			lol -= reset
	except:
		n = 0
	if l[0][1] != None and l[1][2] != None:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		if (lany + l[0][1]) * l[1][2] == midnight or l[0][1] + lany * l[1][2] == midnight:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
	if l[0][2] != None and l[1][1] != None:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		if (lany + l[0][2]) * l[1][1] == midnight or l[0][2] + lany * l[1][1] == midnight:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
	if l[0][0] != None and l[1][2] != None:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		if (lauv + l[0][0]) * l[1][2] == raspberry or l[0][0] + lauv * l[1][2] == raspberry:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
	if l[0][2] != None and l[1][0] != None:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		if (lauv + l[0][2]) * l[1][0] == raspberry or l[0][2] + lauv * l[1][0] == raspberry:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
	if l[0][0] != None and l[1][1] != None:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		if (nightly + l[0][0]) * l[1][1] == pineapple or l[0][0] + nightly * l[1][1] == pineapple:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
	if l[0][1] != None and l[1][0] != None:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		if (nightly + l[0][1]) * l[1][0] == pineapple or l[0][1] + nightly * l[1][0] == pineapple:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			return True
	return False
t = int(input())
lol = lol + lmao
lmao = reset
lol -= reset
while t:
	lol = lol + lmao
	lmao = reset
	lol -= reset
	t -= 1
	lol = lol + lmao
	lmao = reset
	lol -= reset
	(lany, lauv, nightly) = map(int, input().split())
	(midnight, raspberry, pineapple) = map(int, input().split())
	lol = lol + lmao
	lmao = reset
	lol -= reset
	ones = 0
	lol = lol + lmao
	lmao = reset
	lol -= reset
	zeros = 0
	lol = lol + lmao
	lmao = reset
	lol -= reset
	x = midnight - lany
	lol = lol + lmao
	lmao = reset
	lol -= reset
	y = raspberry - lauv
	lol = lol + lmao
	lmao = reset
	lol -= reset
	z = pineapple - nightly
	lol = lol + lmao
	lmao = reset
	lol -= reset
	try:
		if midnight % lany == 0:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			x2 = midnight // lany
			lol = lol + lmao
			lmao = reset
			lol -= reset
		else:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			x2 = 75.8463
			lol = lol + lmao
			lmao = reset
			lol -= reset
	except:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		x2 = 75.8463
		lol = lol + lmao
		lmao = reset
		lol -= reset
	try:
		if raspberry % lauv == 0:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			y2 = raspberry // lauv
			lol = lol + lmao
			lmao = reset
			lol -= reset
		else:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			y2 = 857.949
			lol = lol + lmao
			lmao = reset
			lol -= reset
	except:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		y2 = 857.949
		lol = lol + lmao
		lmao = reset
		lol -= reset
	try:
		if pineapple % nightly == 0:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			z2 = pineapple // nightly
			lol = lol + lmao
			lmao = reset
			lol -= reset
		else:
			lol = lol + lmao
			lmao = reset
			lol -= reset
			z2 = 553.7465
			lol = lol + lmao
			lmao = reset
			lol -= reset
	except:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		z2 = 553.7465
		lol = lol + lmao
		lmao = reset
		lol -= reset
	twins = 0
	if lany == midnight:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		twins += 1
		lol = lol + lmao
		lmao = reset
		lol -= reset
	if lauv == raspberry:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		twins += 1
		lol = lol + lmao
		lmao = reset
		lol -= reset
	if nightly == pineapple:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		twins += 1
		lol = lol + lmao
		lmao = reset
		lol -= reset
	if twins == 3:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(0)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif twins == 2:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(1)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif twins == 1 and (x == y or y == z or z == x):
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(1)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif twins == 1 and (x2 == y2 and math.ceil(x2) == x2 or (y2 == z2 and math.ceil(y2) == y2) or (z2 == x2 and math.ceil(x2) == x2)):
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(1)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif twins == 0 and x == y == z:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(1)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif twins == 0 and (x2 == y2 == z2 and math.ceil(x2) == x2):
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(1)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif midnight == raspberry == pineapple == 0:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(1)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif midnight == raspberry == 0 and nightly == pineapple:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(1)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif raspberry == pineapple == 0 and lany == midnight:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(1)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif pineapple == midnight == 0 and lauv == raspberry:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(1)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif check1(lany, lauv, nightly, midnight, raspberry, pineapple) or check2(x, y, z, x2, y2, z2) or check3(lany, lauv, nightly, midnight, raspberry, pineapple) or check4(lany, lauv, nightly, midnight, raspberry, pineapple):
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(2)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif twins == 1 and lany == midnight and (y != z):
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(2)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif twins == 1 and lauv == raspberry and (x != z):
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(2)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif twins == 1 and nightly == pineapple and (x != y):
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(2)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif twins == 0 and (x == y or y == z or z == x):
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(2)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif twins == 1 and lany == midnight and (y2 != z2 or math.ceil(y2) != y2):
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(2)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif twins == 1 and lauv == raspberry and (x2 != z2 or math.ceil(x2) != x2):
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(2)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif twins == 1 and nightly == pineapple and (x2 != y2 or math.ceil(x2) != x2):
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(2)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	elif twins == 0 and (x2 == y2 and math.ceil(x2) == x2 or (y2 == z2 and math.ceil(y2) == y2) or (z2 == x2 and math.ceil(x2) == x2)):
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(2)
		lol = lol + lmao
		lmao = reset
		lol -= reset
	else:
		lol = lol + lmao
		lmao = reset
		lol -= reset
		print(3)
		lol = lol + lmao
		lmao = reset
		lol -= reset


t = int(input())
while t > 0:
	t = t - 1
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	if a == p and b == q and (c == r):
		print(0)
		continue
	d1 = a - p
	d2 = b - q
	d3 = c - r
	if d1 == 0 and d2 == 0 and (d3 != 0) or (d1 != 0 and d2 == 0 and (d3 == 0)) or (d1 == 0 and d2 != 0 and (d3 == 0)):
		print(1)
		continue
	if d1 == 0 and d2 != 0 and (d3 != 0) and (d2 == d3) or (d2 == 0 and d3 != 0 and (d1 != 0) and (d1 == d3)) or (d3 == 0 and d1 != 0 and (d2 != 0) and (d1 == d2)):
		print(1)
		continue
	if d1 == 0 and d2 != 0 and (d3 != 0):
		if q != 0 and r != 0:
			if b % q == 0 and c % r == 0:
				if b / q == c / r:
					print(1)
					continue
	if d2 == 0 and d1 != 0 and (d3 != 0):
		if p != 0 and r != 0:
			if a % p == 0 and c % r == 0:
				if a / p == c / r:
					print(1)
					continue
	if d3 == 0 and d2 != 0 and (d1 != 0):
		if q != 0 and p != 0:
			if b % q == 0 and a % p == 0:
				if b / q == a / p:
					print(1)
					continue
	if d3 != 0 and d2 != 0 and (d1 != 0) and (d1 == d2) and (d2 == d3):
		print(1)
		continue
	if d3 != 0 and d2 != 0 and (d1 != 0):
		if p != 0 and q != 0 and (r != 0):
			if a % p == 0 and b % q == 0 and (c % r == 0):
				if a / p == b / q == c / r:
					print(1)
					continue
	if d1 == 0 and d2 != d3 or (d2 == 0 and d3 != d1) or (d3 == 0 and d1 != d2):
		print(2)
		continue
	if d1 == 0 and q != 0 and (r != 0):
		if b % q == 0 and c % r == 0:
			if b / q != c / r:
				print(2)
				continue
	if d2 == 0 and p != 0 and (r != 0):
		if a % p == 0 and c % r == 0:
			if a / p != c / r:
				print(2)
				continue
	if d3 == 0 and p != 0 and (q != 0):
		if b % q == 0 and a % p == 0:
			if b / q != a / p:
				print(2)
				continue
	if d1 == d2 != d3 != 0 or d2 == d3 != d1 != 0 or d1 == d3 != d2 != 0:
		print(2)
		continue
	if p != 0 and q != 0 and (d1 != 0) and (d2 != 0) and (d3 != 0):
		if a % p == 0 and b % q == 0:
			if a / p == b / q:
				print(2)
				continue
	if p != 0 and r != 0 and (d1 != 0) and (d2 != 0) and (d3 != 0):
		if a % p == 0 and c % r == 0:
			if a / p == c / r:
				print(2)
				continue
	if r != 0 and q != 0 and (d1 != 0) and (d2 != 0) and (d3 != 0):
		if c % r == 0 and b % q == 0:
			if c / r == b / q:
				print(2)
				continue
	if d1 + d2 == d3 or d2 + d3 == d1 or d3 + d1 == d2:
		print(2)
		continue
	if p != 0 and q != 0 and (r != 0):
		if a % p == 0 and b % q == 0 and (c % r == 0):
			if a / p * (b / q) == c / r or a / p * (c / r) == b / q or c / r * (b / q) == a / p:
				print(2)
				continue
	if q != 0:
		if b % q == 0 and (r * (b / q) + d1 == c or (r + d1) * (b / q) == c):
			print(2)
			continue
	if q != 0:
		if b % q == 0 and (p * (b / q) + d3 == a or (p + d3) * (b / q) == a):
			print(2)
			continue
	if p != 0:
		if a % p == 0 and (r * (a / p) + d2 == c or (r + d2) * (a / p) == c):
			print(2)
			continue
	if p != 0:
		if a % p == 0 and (q * (a / p) + d3 == b or (q + d3) * (a / p) == b):
			print(2)
			continue
	if r != 0:
		if c % r == 0 and (q * (c / r) + d1 == b or (q + d1) * (c / r) == b):
			print(2)
			continue
	if r != 0:
		if c % r == 0 and (p * (c / r) + d2 == a or (p + d2) * (c / r) == a):
			print(2)
			continue
	if p - q != 0 and a - b != 0:
		if (a - b) % (p - q) == 0:
			m = (a - b) / (p - q)
			if (p * b - a * q) % (a - b) == 0:
				d = (p * b - a * q) / (a - b)
				if (p + d) * m == a and (q + d) * m == b and (r + d == c or r * m == c or (r + d) * m == c):
					print(2)
					continue
	if p - r != 0 and a - c != 0:
		if (a - c) % (p - r) == 0:
			m = (a - c) / (p - r)
			if (p * c - a * r) % (a - c) == 0:
				d = (p * c - a * r) / (a - c)
				if (p + d) * m == a and (r + d) * m == c and (q + d == b or q * m == b or (q + d) * m == b):
					print(2)
					continue
	if q - r != 0 and b - c != 0:
		if (b - c) % (q - r) == 0:
			m = (b - c) / (q - r)
			if (q * c - b * r) % (b - c) == 0:
				d = (q * c - b * r) / (b - c)
				if (q + d) * m == b and (r + d) * m == c and (p + d == a or p * m == a or (p + d) * m == a):
					print(2)
					continue
	if p - q != 0:
		if (a - b) % (p - q) == 0:
			m = (a - b) / (p - q)
			if (p * b - a * q) % (p - q) == 0:
				d = (p * b - a * q) / (p - q)
				if p * m + d == a and q * m + d == b and (r + d == c or r * m == c or r * m + d == c):
					print(2)
					continue
	if p - r != 0:
		if (a - c) % (p - r) == 0:
			m = (a - c) / (p - r)
			if (p * c - a * r) % (p - r) == 0:
				d = (p * c - a * r) / (p - r)
				if p * m + d == a and r * m + d == c and (q + d == b or q * m == b or q * m + d == b):
					print(2)
					continue
	if q - r != 0:
		if (b - c) % (q - r) == 0:
			m = (b - c) / (q - r)
			if (q * c - b * r) % (q - r) == 0:
				d = (q * c - b * r) / (q - r)
				if r * m + d == c and q * m + d == b and (p + d == a or p * m == a or p * m + d == a):
					print(2)
					continue
	print(3)


def performCheck4(p, q, r, a, b, c):
	x = c - r
	if p != 0 and q != 0 and ((a - x) % p == 0) and ((b - x) % q == 0) and ((a - x) // p == (b - x) // q):
		return True
	elif p != 0 and q != 0 and ((a - x) % p == 0) and (b % q == 0) and ((a - x) // p == b // q):
		return True
	elif p != 0 and q != 0 and ((b - x) % q == 0) and (a % p == 0) and ((b - x) // q == a // p):
		return True
	elif p != 0 and q != 0 and (a % p == 0) and (b % q == 0) and (a // p == b // q):
		return True
	x = b - q
	if p != 0 and r != 0 and ((a - x) % p == 0) and ((c - x) % r == 0) and (p != 0) and (r != 0) and ((a - x) // p == (c - x) // r):
		return True
	elif p != 0 and r != 0 and ((a - x) % p == 0) and (c % r == 0) and ((a - x) // p == c // r):
		return True
	elif p != 0 and r != 0 and ((c - x) % r == 0) and (a % p == 0) and ((c - x) // r == a // p):
		return True
	elif p != 0 and r != 0 and (a % p == 0) and (c % r == 0) and (a // p == c // r):
		return True
	x = a - p
	if q != 0 and r != 0 and ((b - x) % q == 0) and ((c - x) % r == 0) and ((b - x) // q == (c - x) // r):
		return True
	elif q != 0 and r != 0 and ((b - x) % q == 0) and (c % r == 0) and ((b - x) // q == c // r):
		return True
	elif q != 0 and r != 0 and ((c - x) % r == 0) and (b % q == 0) and ((c - x) // r == b // q):
		return True
	elif q != 0 and r != 0 and (b % q == 0) and (c % r == 0) and (b // q == c // r):
		return True
	if r != 0 and c % r == 0:
		y = c // r
		if a - p * y == b - q * y:
			return True
	if q != 0 and b % q == 0:
		y = b // q
		if a - p * y == c - r * y:
			return True
	if p != 0 and a % p == 0:
		y = a // p
		if b - q * y == c - r * y:
			return True
	if p != q and (a - b) % (p - q) == 0:
		y = (a - b) // (p - q)
		x = a - p * y
		if r * y + x == c and q * y + x == b:
			return True
	return False

def performCheck3(p, q, r, a, b, c):
	if r != 0 and c != 0 and (c % r == 0):
		y = c // r
		if y != 0:
			if a % y == 0 and b % y == 0 and (a // y - p == b // y - q):
				return True
			elif a % y == 0 and a // y - p == b - q:
				return True
			elif b % y == 0 and b // y - q == a - p:
				return True
	if q != 0 and b != 0 and (b % q == 0):
		y = b // q
		if y != 0:
			if a % y == 0 and c % y == 0 and (a // y - p == c // y - r):
				return True
			elif a % y == 0 and a // y - p == c - r:
				return True
			elif c % y == 0 and c // y - r == a - p:
				return True
	if p != 0 and a != 0 and (a % p == 0):
		y = a // p
		if y != 0:
			if b % y == 0 and c % y == 0 and (b // y - q == c // y - r):
				return True
			elif b % y == 0 and b // y - q == c - r:
				return True
			elif c % y == 0 and c // y - r == b - q:
				return True
	x = c - r
	if p + x != 0 and q + x != 0 and (a % (p + x) == 0) and (b % (q + x) == 0) and (a // (p + x) == b // (q + x)):
		return True
	x = b - q
	if p + x != 0 and r + x != 0 and (a % (p + x) == 0) and (c % (r + x) == 0) and (a // (p + x) == c // (r + x)):
		return True
	x = a - p
	if q + x != 0 and r + x != 0 and (b % (q + x) == 0) and (c % (r + x) == 0) and (b // (q + x) == c // (r + x)):
		return True
	if p != q and a != b and ((a - b) % (p - q) == 0):
		y = (a - b) // (p - q)
		x = a // y - p
		if (r + x) * y == c and (q + x) * y == b:
			return True
	return False

def performCheck2(p, q, r, a, b, c):
	if p != 0 and q != 0 and (r != 0) and (a % p == 0) and (b % q == 0) and (c % r == 0):
		(x, y, z) = (a // p, b // q, c // r)
		if x == 1 or y == 1 or z == 1 or (x == y) or (y == z) or (x == z) or (x * y == z) or (x * z == y) or (y * z == x):
			return True
	return False

def performCheck1(p, q, r, a, b, c):
	(x, y, z) = (p - a, q - b, r - c)
	if x == 0 or y == 0 or z == 0 or (x == y) or (y == z) or (x == z) or (x + y == z) or (x + z == y) or (y + z == x):
		return True
	return False

def performCheck(p, q, r, a, b, c):
	(x, y, z) = (a - p, b - q, c - r)
	if x == 0 and y == z or (y == 0 and x == z) or (z == 0 and x == y) or (x == 0 and y == 0) or (x == 0 and z == 0) or (y == 0 and z == 0) or (x == y == z):
		return True
	elif p != 0 and q != 0 and (r != 0) and (a % p == 0) and (b % q == 0) and (c % r == 0):
		(x, y, z) = (a // p, b // q, c // r)
		if x == 1 and y == z or (y == 1 and x == z) or (z == 1 and x == y) or (x == 1 and y == 1) or (x == 1 and z == 1) or (y == 1 and z == 1) or (x == y == z):
			return True
	elif p == 0 and a == 0:
		if q != 0 and r != 0 and (b % q == 0) and (c % r == 0) and (b // q == c // r):
			return True
	elif q == 0 and b == 0:
		if p != 0 and r != 0 and (a % p == 0) and (c % r == 0) and (a // p == c // r):
			return True
	elif r == 0 and c == 0:
		if p != 0 and q != 0 and (a % p == 0) and (b % q == 0) and (a // p == b // q):
			return True
	return False
T = int(input())
for _ in range(T):
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	if p == a and q == b and (r == c):
		print(0)
	elif performCheck(p, q, r, a, b, c) or (a == 0 and b == 0 and (c == 0)):
		print(1)
	elif performCheck1(p, q, r, a, b, c) or performCheck2(p, q, r, a, b, c) or performCheck3(p, q, r, a, b, c) or performCheck4(p, q, r, a, b, c):
		print(2)
	else:
		print(3)


import math

def floored(x):
	y = math.floor(math.sqrt(abs(x)))
	return 1 + y

def starplus(l1, l2, extra, v):
	d = l2[0] - l1[0]
	if l1[0] != 0:
		if l1[1] != 0 and (l2[1] - d) % l1[1] == 0:
			k = (l2[1] - d) // l1[1]
			if l1[2] * k == l2[2] or l1[2] * k + d == l2[2]:
				v = min(2, v)
		if l1[1] != 0 and l2[1] % l1[1] == 0:
			k = l2[1] // l1[1]
			if l2[2] == l1[2] * k or l1[2] * k + d == l2[2]:
				v = min(2, v)
	d = l2[1] - l1[1]
	if l1[1] != 0:
		if l1[0] != 0 and (l2[0] - d) % l1[0] == 0:
			k = (l2[0] - d) // l1[0]
			if l1[2] * k == l2[2] or l1[2] * k + d == l2[2]:
				v = min(2, v)
		if l1[0] != 0 and l2[0] % l1[0] == 0:
			k = l2[0] // l1[0]
			if l2[2] == l1[2] * k or l2[2] == l1[2] * k + d:
				v = min(2, v)
	d = l2[2] - l1[2]
	if l1[2] != 0:
		if l1[0] != 0 and (l2[0] - d) % l1[0] == 0:
			k = (l2[0] - d) // l1[0]
			if l1[1] * k == l2[1] or l1[1] * k + d == l2[1]:
				v = min(2, v)
		if l1[0] != 0 and l2[0] % l1[0] == 0:
			k = l2[0] // l1[0]
			if l1[1] * k == l2[1] or l1[1] * k + d == l2[1]:
				v = min(2, v)
	if l1[1] - l1[0] != 0 and (l2[1] - l2[0]) % (l1[1] - l1[0]) == 0:
		q = (l2[1] - l2[0]) // (l1[1] - l1[0])
		d = l2[1] - l1[1] * q
		if l2[2] == l1[2] * q + d or l2[2] == l1[2] * q or l2[2] == l1[2] + d:
			v = min(2, v)
	if l1[2] - l1[1] != 0 and (l2[2] - l2[1]) % (l1[2] - l1[1]) == 0:
		q = (l2[2] - l2[1]) // (l1[2] - l1[1])
		d = l2[1] - l1[1] * q
		if l2[0] == l1[0] * q + d or l2[0] == l1[0] * q or l2[0] == l1[0] + d:
			v = min(2, v)
	if l1[2] - l1[0] != 0 and (l2[2] - l2[0]) % (l1[2] - l1[0]) == 0:
		q = (l2[2] - l2[0]) // (l1[2] - l1[0])
		d = l2[2] - l1[2] * q
		if l2[1] == l1[1] * q + d or l2[1] == l1[1] * q or l2[1] == l1[1] + d:
			v = min(2, v)
	return v

def check(zing, l1, l2):
	v = 3
	d1 = l2[0] - l1[0]
	d2 = l2[1] - l1[1]
	d3 = l2[2] - l1[2]
	if d1 == d2 and d1 == d3:
		v = 1
	elif d1 == d2 or d2 == d3 or d1 == d3 or (d1 == d2 + d3) or (d2 == d1 + d3) or (d3 == d1 + d2):
		v = 2
	q1 = 10000000000.0
	q2 = 10000000000.0
	q3 = 10000000000.0
	if l1[0] != 0 and l2[0] % l1[0] == 0:
		q1 = l2[0] // l1[0]
	if l1[1] != 0 and l2[1] % l1[1] == 0:
		q2 = l2[1] // l1[1]
	if l1[2] != 0 and l2[2] % l1[2] == 0:
		q3 = l2[2] // l1[2]
	if q1 == q2 and q2 == q3 and (q1 != 10000000000.0):
		v = min(1, v)
	if q1 == q2 and q1 != 10000000000.0 or (q2 == q3 and q2 != 10000000000.0) or (q1 == q3 and q1 != 10000000000.0):
		v = min(2, v)
	if q1 != 10000000000.0 and q2 != 10000000000.0 and (q3 != 10000000000.0) and (q1 * q2 == q3 or q1 * q3 == q2 or q2 * q3 == q1):
		v = min(2, v)
	f1 = []
	f2 = []
	f3 = []
	for i in range(1, floored(l2[0])):
		if l2[0] % i == 0:
			f1.append(i)
			f1.append(l2[0] // i)
			i *= -1
			f1.append(i)
			f1.append(l2[0] // i)
	for i in range(1, floored(l2[1])):
		if l2[1] % i == 0:
			f2.append(i)
			f2.append(l2[1] // i)
			i *= -1
			f2.append(i)
			f2.append(l2[1] // i)
	for i in range(1, floored(l2[2])):
		if l2[2] % i == 0:
			f3.append(i)
			f3.append(l2[2] // i)
			i *= -1
			f3.append(i)
			f3.append(l2[2] // i)
	f1 = list(set(f1))
	f2 = list(set(f2))
	f3 = list(set(f3))
	v = min(v, starplus(l1, l2, 1, v))
	for i in f1:
		if i != 0 and l2[0] % i == 0:
			x = l2[0] // i - l1[0]
		else:
			x = l2[0] - l1[0]
		if l2[1] - l1[1] == x or (i != 0 and l2[1] % i == 0 and (l2[1] // i - l1[1] == 0 or l2[1] // i - l1[1] == x)):
			if l2[2] - l1[2] == x or (i != 0 and l2[2] % i == 0 and (l2[2] // i - l1[2] == 0 or l2[2] // i - l1[2] == x)):
				v = min(2, v)
	for i in f2:
		if i != 0 and l2[1] % i == 0:
			x = l2[1] // i - l1[1]
		else:
			x = l2[1] - l1[1]
		if l2[0] - l1[0] == x or (i != 0 and l2[0] % i == 0 and (l2[0] // i - l1[0] == 0 or l2[0] // i - l1[0] == x)):
			if l2[2] - l1[2] == x or (i != 0 and l2[2] % i == 0 and (l2[2] // i - l1[2] == 0 or l2[2] // i - l1[2] == x)):
				v = min(2, v)
	for i in f3:
		if i != 0 and l2[2] % i == 0:
			x = l2[2] // i - l1[2]
		else:
			x = l2[2] - l1[2]
		if l2[0] - l1[0] == x or (i != 0 and l2[0] % i == 0 and (l2[0] // i - l1[0] == 0 or l2[0] // i - l1[0] == x)):
			if l2[1] - l1[1] == x or (i != 0 and l2[1] % i == 0 and (l2[1] // i - l1[1] == 0 or l2[1] // i - l1[1] == x)):
				v = min(2, v)
	return v

def push(a, b, under):
	l1 = list()
	l2 = []
	if a[0] != b[0]:
		l1.append(a[0])
		l2.append(b[0])
	if a[1] != b[1]:
		l1.append(a[1])
		l2.append(b[1])
	if a[2] != b[2]:
		l1.append(a[2])
		l2.append(b[2])
	v = 3
	if len(l1) == 0:
		v = 0
	elif len(l1) == 1:
		v = 1
	elif len(l1) == 2:
		v = 2
		d1 = l2[0] - l1[0]
		d2 = l2[1] - l1[1]
		if d1 == d2:
			v = 1
		if l1[0] != 0 and l1[1] != 0 and (l2[1] % l1[1] == 0) and (l2[0] % l1[0] == 0):
			q1 = l2[0] // l1[0]
			q2 = l2[1] // l1[1]
			if q1 == q2:
				v = 1
	elif len(l1) == 3:
		v = check(1, l1, l2)
	print(v)
for _ in range(int(input())):
	t1 = list(map(int, input().split()))
	t2 = list(map(int, input().split()))
	push(t1, t2, 1)


def check2(a, b, c, d):
	if c - a == d - b:
		return 1
	if a == 0 or b == 0:
		return 0
	if c % a == 0 and d % b == 0 and (c // a == d // b):
		return 1
	return 0

def check3(a, b, c, d, e, f):
	if d - a == e - b and e - b == f - c:
		return 1
	if a == 0 or b == 0 or c == 0:
		return 0
	if d % a == 0 and e % b == 0 and (f % c == 0) and (d // a == e // b) and (e // b == f // c):
		return 1
	return 0
t = int(input())
while t:
	t -= 1
	(a, b, c) = [int(x) for x in input().split()]
	(a1, b1, c1) = [int(x) for x in input().split()]
	if a == a1 and b == b1 and (c == c1):
		print('0')
		continue
	if a == a1 and b == b1 or (a == a1 and c == c1) or (b == b1 and c == c1):
		print('1')
		continue
	if a == a1 and check2(b, c, b1, c1) or (b == b1 and check2(a, c, a1, c1)) or (c == c1 and check2(a, b, a1, b1)) or check3(a, b, c, a1, b1, c1):
		print('1')
		continue
	if a == a1 or b == b1 or c == c1:
		print('2')
		continue
	if check2(a, b, a1, b1) or check2(a, c, a1, c1) or check2(b, c, b1, c1):
		print('2')
		continue
	d1 = a1 - a
	d2 = b1 - b
	d3 = c1 - c
	if d1 + d2 == d3 or d2 + d3 == d1 or d1 + d3 == d2:
		print('2')
		continue
	flag = 1
	if a == 0 or b == 0 or c == 0:
		flag = 0
	if flag == 1:
		div1 = a1 // a
		div2 = b1 // b
		div3 = c1 // c
		mod1 = a1 % a
		mod2 = b1 % b
		mod3 = c1 % c
		if mod1 == 0 and mod2 == 0 and (mod3 == 0) and (div1 * div2 == div3 or div1 * div3 == div2 or div2 * div3 == div1):
			print('2')
			continue
	if a != 0 and a1 % a == 0:
		div1 = a1 // a
		if div1 != 0 and c1 % div1 == 0:
			if b1 - b == c1 // div1 - c:
				print('2')
				continue
		if div1 != 0 and b1 % div1 == 0:
			if c1 - c == b1 // div1 - b:
				print('2')
				continue
	if b != 0 and b1 % b == 0:
		div1 = b1 // b
		if div1 != 0 and c1 % div1 == 0:
			if a1 - a == c1 // div1 - c:
				print('2')
				continue
		if div1 != 0 and a1 % div1 == 0:
			if c1 - c == a1 // div1 - a:
				print('2')
				continue
	if c != 0 and c1 % c == 0:
		div1 = c1 // c
		if div1 != 0 and a1 % div1 == 0:
			if b1 - b == a1 // div1 - a:
				print('2')
				continue
		if div1 != 0 and b1 % div1 == 0:
			if a1 - a == b1 // div1 - b:
				print('2')
				continue
	if a != 0 and (a1 - d2) % a == 0:
		if c != 0 and c1 % c == 0 and ((a1 - d2) // a == c1 // c):
			print('2')
			continue
	if a != 0 and (a1 - d3) % a == 0:
		if b != 0 and b1 % b == 0 and ((a1 - d3) // a == b1 // b):
			print('2')
			continue
	if b != 0 and (b1 - d1) % b == 0:
		if c != 0 and c1 % c == 0 and ((b1 - d1) // b == c1 // c):
			print('2')
			continue
	if b != 0 and (b1 - d3) % b == 0:
		if a != 0 and a1 % a == 0 and ((b1 - d3) // b == a1 // a):
			print('2')
			continue
	if c != 0 and (c1 - d1) % c == 0:
		if b != 0 and b1 % b == 0 and ((c1 - d1) // c == b1 // b):
			print('2')
			continue
	if c != 0 and (c1 - d2) % c == 0:
		if a != 0 and a1 % a == 0 and ((c1 - d2) // c == a1 // a):
			print('2')
			continue
	if a != 0 and a1 % a == 0:
		div1 = a1 // a
		if div1 != 0 and b1 % div1 == 0 and (c1 % div1 == 0):
			div2 = b1 // div1
			div3 = c1 // div1
			if div2 - b == div3 - c:
				print('2')
				continue
	if b != 0 and b1 % b == 0:
		div1 = b1 // b
		if div1 != 0 and a1 % div1 == 0 and (c1 % div1 == 0):
			div2 = a1 // div1
			div3 = c1 // div1
			if div2 - a == div3 - c:
				print('2')
				continue
	if c != 0 and c1 % c == 0:
		div1 = c1 // c
		if div1 != 0 and a1 % div1 == 0 and (b1 % div1 == 0):
			div2 = a1 // div1
			div3 = b1 // div1
			if div2 - a == div3 - b:
				print('2')
				continue
	if b != 0 and c != 0 and ((b1 - d1) % b == 0) and ((c1 - d1) % c == 0) and ((b1 - d1) // b == (c1 - d1) // c):
		print('2')
		continue
	if a != 0 and b != 0 and ((b1 - d3) % b == 0) and ((a1 - d3) % a == 0) and ((b1 - d3) // b == (a1 - d3) // a):
		print('2')
		continue
	if a != 0 and c != 0 and ((a1 - d2) % a == 0) and ((c1 - d2) % c == 0) and ((a1 - d2) // a == (c1 - d2) // c):
		print('2')
		continue
	if b + d1 != 0 and c + d1 != 0 and (b1 % (b + d1) == 0) and (c1 % (c + d1) == 0) and (b1 // (b + d1) == c1 // (c + d1)):
		print('2')
		continue
	if a + d2 != 0 and c + d2 != 0 and (a1 % (a + d2) == 0) and (c1 % (c + d2) == 0) and (a1 // (a + d2) == c1 // (c + d2)):
		print('2')
		continue
	if b + d3 != 0 and a + d3 != 0 and (b1 % (b + d3) == 0) and (a1 % (a + d3) == 0) and (b1 // (b + d3) == a1 // (a + d3)):
		print('2')
		continue
	if a != 0 and a1 % a == 0:
		div1 = a1 // a
		if b1 - b * div1 == c1 - c * div1:
			print('2')
			continue
	if b != 0 and b1 % b == 0:
		div1 = b1 // b
		if a1 - a * div1 == c1 - c * div1:
			print('2')
			continue
	if c != 0 and c1 % c == 0:
		div1 = c1 // c
		if b1 - b * div1 == a1 - a * div1:
			print('2')
			continue
	if a - b != 0 and (a1 - b1) % (a - b) == 0:
		y1 = (a1 - b1) // (a - b)
		if y1 != 0 and a1 % y1 == 0:
			x1 = a1 // y1 - a
			if (c + x1) * y1 == c1:
				print('2')
				continue
	if a - c != 0 and (a1 - c1) % (a - c) == 0:
		y1 = (a1 - c1) // (a - c)
		if y1 != 0 and a1 % y1 == 0:
			x1 = a1 // y1 - a
			if (b + x1) * y1 == b1:
				print('2')
				continue
	if b - c != 0 and (b1 - c1) % (b - c) == 0:
		y1 = (b1 - c1) // (b - c)
		if y1 != 0 and b1 % y1 == 0:
			x1 = b1 // y1 - b
			if (a + x1) * y1 == a1:
				print('2')
				continue
	if a - b != 0 and (a1 - b1) % (a - b) == 0:
		x1 = (a1 - b1) // (a - b)
		y1 = a1 - a * x1
		if c * x1 + y1 == c1:
			print('2')
			continue
	if a - c != 0 and (a1 - c1) % (a - c) == 0:
		x1 = (a1 - c1) // (a - c)
		y1 = a1 - a * x1
		if b * x1 + y1 == b1:
			print('2')
			continue
	if c - b != 0 and (c1 - b1) % (c - b) == 0:
		x1 = (c1 - b1) // (c - b)
		y1 = c1 - c * x1
		if a * x1 + y1 == a1:
			print('2')
			continue
	print('3')
	continue


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c1 = 0
	for i in range(3):
		if a[i] == b[i]:
			c1 += 1
	if c1 == 3:
		print(0)
		continue
	if c1 == 2:
		print(1)
		continue
	if c1 == 1:
		if a[0] == b[0]:
			if a[1] - b[1] == a[2] - b[2]:
				print(1)
				continue
			if a[2] != 0 and a[1] != 0 and (b[2] / a[2] == b[1] / a[1]) and (b[2] % a[2] == 0) and (b[1] % a[1] == 0):
				print(1)
				continue
		if a[1] == b[1]:
			if a[0] - b[0] == a[2] - b[2]:
				print(1)
				continue
			if a[0] != 0 and a[2] != 0 and (b[2] / a[2] == b[0] / a[0]) and (b[2] % a[2] == 0) and (b[0] % a[0] == 0):
				print(1)
				continue
		if a[2] == b[2]:
			if a[1] - b[1] == a[0] - b[0]:
				print(1)
				continue
			if a[0] != 0 and a[1] != 0 and (b[0] / a[0] == b[1] / a[1]) and (b[0] % a[0] == 0) and (b[1] % a[1] == 0):
				print(1)
				continue
		print(2)
		continue
	if c1 == 0:
		s = set()
		mylove = []
		for i in range(3):
			if a[i] != b[i]:
				s.add(b[i] - a[i])
		if len(s) == 1:
			print(1)
			continue
		s.clear()
		c2 = 0
		for i in range(3):
			if a[i] != 0 and b[i] % a[i] == 0 and (b[i] != a[i]):
				s.add(b[i] // a[i])
			else:
				c2 += 1
		if len(s) == 1 and c2 == 0:
			print(1)
			continue
		s.clear()
		for i in range(3):
			if a[i] != b[i]:
				s.add(b[i] - a[i])
				mylove.append(b[i] - a[i])
		if len(s) == 2:
			print(2)
			continue
		if len(s) == 3:
			if mylove[0] == mylove[1] + mylove[2] or mylove[1] == mylove[0] + mylove[2] or mylove[2] == mylove[0] + mylove[1]:
				print(2)
				continue
		s.clear()
		mylove.clear()
		c2 = 0
		for i in range(3):
			if a[i] != 0 and b[i] % a[i] == 0:
				s.add(b[i] / a[i])
				mylove.append(b[i] / a[i])
			else:
				c2 += 1
		if len(s) == 2 and c2 == 0:
			print(2)
			continue
		if len(s) == 3:
			if mylove[0] == mylove[1] * mylove[2] or mylove[1] == mylove[0] * mylove[2] or mylove[2] == mylove[0] * mylove[1]:
				print(2)
				continue
		if len(s) == 1 and c2 == 1:
			print(2)
			continue
		r1 = a[0] - a[1]
		r2 = b[0] - b[1]
		if r1 != 0 and r2 % r1 == 0:
			x = r2 // r1
			y = b[0] - a[0] * x
			if a[2] * x + y == b[2]:
				print(2)
				continue
		if a[0] != 0 and b[0] % a[0] == 0:
			k = b[0] // a[0]
			if b[1] - a[1] * k == b[2] - a[2] * k:
				print(2)
				continue
			if k != 0 and b[1] % k == 0 and (b[2] % k == 0) and (b[1] / k - a[1] == b[2] / k - a[2]):
				print(2)
				continue
		if a[1] != 0 and b[1] % a[1] == 0:
			k = b[1] // a[1]
			if b[0] - a[0] * k == b[2] - a[2] * k:
				print(2)
				continue
			if k != 0 and b[0] % k == 0 and (b[2] % k == 0) and (b[0] / k - a[0] == b[2] / k - a[2]):
				print(2)
				continue
		if a[2] != 0 and b[2] % a[2] == 0:
			k = b[2] // a[2]
			if b[1] - a[1] * k == b[0] - a[0] * k:
				print(2)
				continue
			if k != 0 and b[1] % k == 0 and (b[0] % k == 0) and (b[1] / k - a[1] == b[0] / k - a[0]):
				print(2)
				continue
		poo = b[0] - a[0]
		agra = b[1] - poo
		him = b[2] - poo
		if a[1] != 0 and a[2] != 0 and (agra % a[1] == 0) and (him % a[2] == 0) and (agra / a[1] == him / a[2]):
			print(2)
			continue
		ram = a[1] + poo
		shyam = a[2] + poo
		if ram != 0 and shyam != 0 and (b[1] % ram == 0) and (b[2] % shyam == 0) and (b[1] / ram == b[2] / shyam):
			print(2)
			continue
		poo = b[1] - a[1]
		agra = b[0] - poo
		him = b[2] - poo
		if a[0] != 0 and a[2] != 0 and (agra % a[0] == 0) and (him % a[2] == 0) and (agra / a[0] == him / a[2]):
			print(2)
			continue
		ram = a[0] + poo
		shyam = a[2] + poo
		if ram != 0 and shyam != 0 and (b[0] % ram == 0) and (b[2] % shyam == 0) and (b[0] / ram == b[2] / shyam):
			print(2)
			continue
		poo = b[2] - a[2]
		agra = b[1] - poo
		him = b[0] - poo
		if a[1] != 0 and a[0] != 0 and (agra % a[1] == 0) and (him % a[0] == 0) and (agra / a[1] == him / a[0]):
			print(2)
			continue
		ram = a[1] + poo
		shyam = a[0] + poo
		if ram != 0 and shyam != 0 and (b[1] % ram == 0) and (b[0] % shyam == 0) and (b[1] / ram == b[0] / shyam):
			print(2)
			continue
		dinesh = b[0] - a[0]
		if a[1] != 0 and b[1] % a[1] == 0:
			zz = b[1] // a[1]
			if a[2] * zz + dinesh == b[2]:
				print(2)
				continue
			if (a[2] + dinesh) * zz == b[2]:
				print(2)
				continue
		if a[2] != 0 and b[2] % a[2] == 0:
			zz = b[2] // a[2]
			if a[1] * zz + dinesh == b[1]:
				print(2)
				continue
			if (a[1] + dinesh) * zz == b[1]:
				print(2)
				continue
		dinesh = b[1] - a[1]
		if a[0] != 0 and b[0] % a[0] == 0:
			zz = b[0] / a[0]
			if a[2] * zz + dinesh == b[2]:
				print(2)
				continue
			if (a[2] + dinesh) * zz == b[2]:
				print(2)
				continue
		if a[2] != 0 and b[2] % a[2] == 0:
			zz = b[2] / a[2]
			if a[0] * zz + dinesh == b[0]:
				print(2)
				continue
			if (a[0] + dinesh) * zz == b[0]:
				print(2)
				continue
		dinesh = b[2] - a[2]
		if a[1] != 0 and b[1] % a[1] == 0:
			zz = b[1] / a[1]
			if a[0] * zz + dinesh == b[0]:
				print(2)
				continue
			if (a[0] + dinesh) * zz == b[0]:
				print(2)
				continue
		if a[0] != 0 and b[0] % a[0] == 0:
			zz = b[0] / a[0]
			if a[1] * zz + dinesh == b[1]:
				print(2)
				continue
			if (a[1] + dinesh) * zz == b[1]:
				print(2)
				continue
		print(3)
		continue


import math

def solve():
	a = list(map(float, input().split()))
	p = list(map(float, input().split()))
	d = [p[0] - a[0], p[1] - a[1], p[2] - a[2]]
	div = []
	for i in range(3):
		try:
			div.append(p[i] / a[i])
		except:
			div.append(math.nan)
	if d[0] == 0 and d[1] == 0 and (d[2] == 0):
		print(0)
		return
	else:
		if d[0] == d[1] and d[1] == d[2]:
			print(1)
			return
		if div[0].is_integer() and div[1].is_integer() and div[2].is_integer():
			if div[0] == div[1] and div[1] == div[2]:
				print(1)
				return
		for i in range(3):
			(j, k) = ((i + 1) % 3, (i + 2) % 3)
			if d[i] == 0 and d[j] == d[k] or (d[j] == 0 and d[k] == 0):
				print(1)
				return
			if div[j].is_integer() and div[k].is_integer():
				if d[i] == 0 and div[k] == div[j] or (div[j] == 1 and div[k] == 1):
					print(1)
					return
		for i in range(3):
			(j, k) = ((i + 1) % 3, (i + 2) % 3)
			if d[i] == 0:
				print(2)
				return
			if d[j] == d[k]:
				print(2)
				return
			if div[j].is_integer() and div[k].is_integer():
				if div[k] == div[j]:
					print(2)
					return
			if div[j].is_integer() and div[k].is_integer():
				if p[i] == div[j] * div[k] * a[i]:
					print(2)
					return
			if p[i] == d[j] + d[k] + a[i]:
				print(2)
				return
		for i in range(3):
			(j, k) = ((i + 1) % 3, (i + 2) % 3)
			try:
				u = (p[j] - p[k]) / (a[j] - a[k])
			except:
				u = math.nan
			try:
				v = (a[j] * p[k] - p[j] * a[k]) / (a[j] - a[k])
			except:
				v = math.nan
			if u.is_integer():
				if p[i] == a[i] + v or p[i] == a[i] * u or p[i] == a[i] * u + v:
					print(2)
					return
			try:
				u = (p[j] - p[k]) / (a[j] - a[k])
			except:
				u = math.nan
			try:
				v = (a[j] * p[k] - p[j] * a[k]) / (p[j] - p[k])
			except:
				v = math.nan
			if u.is_integer():
				if p[i] == a[i] + v or p[i] == a[i] * u or p[i] == (a[i] + v) * u:
					print(2)
					return
			try:
				u = p[k] / a[k]
			except:
				u = math.nan
			try:
				v = p[j] - a[j] * p[k] / a[k]
			except:
				v = math.nan
			if u.is_integer():
				if p[i] == a[i] + v or p[i] == a[i] * u or p[i] == a[i] * u + v:
					print(2)
					return
			try:
				u = p[j] / a[j]
			except:
				u = math.nan
			try:
				v = p[k] - a[k] * p[j] / a[j]
			except:
				v = math.nan
			if u.is_integer():
				if p[i] == a[i] + v or p[i] == a[i] * u or p[i] == a[i] * u + v:
					print(2)
					return
			try:
				u = p[k] / a[k]
			except:
				u = math.nan
			try:
				v = a[k] * p[j] / p[k] - a[j]
			except:
				v = math.nan
			if u.is_integer():
				if p[i] == a[i] + v or p[i] == a[i] * u or p[i] == (a[i] + v) * u:
					print(2)
					return
			try:
				u = p[j] / a[j]
			except:
				u = math.nan
			try:
				v = a[j] * p[k] / p[j] - a[k]
			except:
				v = math.nan
			if u.is_integer():
				if p[i] == a[i] + v or p[i] == a[i] * u or p[i] == (a[i] + v) * u:
					print(2)
					return
			try:
				u = (p[j] - p[k] + a[k]) / a[j]
			except:
				u = math.nan
			try:
				v = p[k] - a[k]
			except:
				v = math.nan
			if u.is_integer():
				if p[i] == a[i] + v or p[i] == a[i] * u or p[i] == a[i] * u + v:
					print(2)
					return
			try:
				u = (p[k] - p[j] + a[j]) / a[k]
			except:
				u = math.nan
			try:
				v = p[j] - a[j]
			except:
				v = math.nan
			if u.is_integer():
				if p[i] == a[i] + v or p[i] == a[i] * u or p[i] == a[i] * u + v:
					print(2)
					return
			try:
				u = p[j] / (a[j] + p[k] - a[k])
			except:
				u = math.nan
			try:
				v = p[k] - a[k]
			except:
				v = math.nan
			if u.is_integer():
				if p[i] == a[i] + v or p[i] == a[i] * u or p[i] == (a[i] + v) * u:
					print(2)
					return
			try:
				u = p[k] / (a[k] + p[j] - a[j])
			except:
				u = math.nan
			try:
				v = p[j] - a[j]
			except:
				v = math.nan
			if u.is_integer():
				if p[i] == a[i] + v or p[i] == a[i] * u or p[i] == (a[i] + v) * u:
					print(2)
					return
	print(3)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(p, q, r) = map(int, input().split())
	x = p - a
	y = q - b
	z = r - c
	if x == 0 and y == 0 and (z == 0):
		print('0')
	elif p == 0 and q == 0 and (r == 0):
		print('1')
	elif x == 0 and y == 0 and (z != 0) or (y == 0 and z == 0 and (x != 0)) or (z == 0 and x == 0 and (y != 0)):
		print('1')
	elif x == 0:
		if y == z:
			print('1')
		elif b != 0 and c != 0 and (abs(q) >= abs(b)) and (abs(r) >= abs(c)) and (q % b == 0) and (r % c == 0) and (q // b == r // c):
			print('1')
		elif r == 0 and q == 0:
			print('1')
		else:
			print('2')
	elif y == 0:
		if x == z:
			print('1')
		elif a != 0 and c != 0 and (abs(p) >= abs(a)) and (abs(r) >= abs(c)) and (p % a == 0) and (r % c == 0) and (p // a == r // c):
			print('1')
		elif p == 0 and r == 0:
			print('1')
		else:
			print('2')
	elif z == 0:
		if x == y:
			print('1')
		elif b != 0 and a != 0 and (abs(p) >= abs(a)) and (abs(q) >= abs(b)) and (p % a == 0) and (q % b == 0) and (q // b == p // a):
			print('1')
		elif p == 0 and q == 0:
			print('1')
		else:
			print('2')
	elif x == y and y == z and (z == x):
		print('1')
	elif a != 0 and b != 0 and (c != 0) and (abs(p) >= abs(a)) and (abs(q) >= abs(b)) and (abs(r) >= abs(c)) and (p % a == 0) and (q % b == 0) and (r % c == 0) and (p // a == q // b) and (q // b == r // c) and (r // c == p // a):
		print('1')
	elif x == y or y == z or z == x:
		print('2')
	elif p == 0 and q == 0 and (r != 0) or (q == 0 and r == 0 and (p != 0)) or (r == 0 and p == 0 and (q != 0)):
		print('2')
	elif p == 0 and (q == r - c or r == q - b) or (q == 0 and (p == r - c or r == p - a)) or (r == 0 and (q == p - a or p == q - b)):
		print('2')
	elif a != 0 and b != 0 and (abs(q) >= abs(b)) and (abs(p) >= abs(a)) and (p % a == 0) and (q % b == 0) and (p // a == q // b) or (b != 0 and c != 0 and (abs(r) >= abs(c)) and (abs(q) >= abs(b)) and (r % c == 0) and (q % b == 0) and (r // c == q // b)) or (a != 0 and c != 0 and (abs(p) >= abs(a)) and (abs(r) >= abs(c)) and (p % a == 0) and (r % c == 0) and (p // a == r // c)):
		print('2')
	elif a != 0 and b != 0 and (c != 0) and (abs(q) >= abs(b)) and (abs(p) >= abs(a)) and (abs(r) >= abs(c)) and (p % a == q % b) and (q % b == r % c) and (r % c == p % a) and (p // a == q // b) and (q // b == r // c) and (r // c == p // a):
		print('2')
	elif b - a != 0 and c - b != 0 and (c - a != 0) and ((q - p) // (b - a) == (r - q) // (c - b)) and ((r - q) // (c - b) == (r - p) // (c - a)) and ((r - p) // (c - a) == (q - p) // (b - a)) and ((q - p) // (b - a) != 0) and (p // ((q - p) // (b - a)) - a == q // ((q - p) // (b - a)) - b) and (q // ((q - p) // (b - a)) - b == r // ((q - p) // (b - a)) - c) and (r // ((q - p) // (b - a)) - c == p // ((q - p) // (b - a)) - a):
		print('2')
	elif p == q and q == r and (p == r):
		print('2')
	elif c != 0 and r % c == 0 and ((b + x) * (r // c) == q or (a + y) * (r // c) == p) or (b != 0 and q % b == 0 and ((a + z) * (q // b) == p or (c + x) * (q // b) == r)) or (a != 0 and p % a == 0 and ((b + z) * (p // a) == q or (c + y) * (p // a) == r)):
		print('2')
	elif c != 0 and r % c == 0 and (b * (r // c) + x == q or a * (r // c) + y == p) or (b != 0 and q % b == 0 and (a * (q // b) + z == p or c * (q // b) + x == r)) or (a != 0 and p % a == 0 and (b * (p // a) + z == q or c * (p // a) + y == r)):
		print('2')
	elif a != 0 and b != 0 and (c != 0) and (p % a == q % b) and (q % b == r % c) and (r % c == p % a) and (p // a == 1 and q // b == r // c or (q // b == 1 and p // a == r // c) or (r // c == 1 and p // a == q // b)):
		print('2')
	elif x + y == z or x + z == y or y + z == x:
		print('2')
	elif a != 0 and b != 0 and (c != 0) and (abs(p) >= abs(a)) and (abs(q) >= abs(b)) and (abs(r) >= abs(c)) and (p % a == 0) and (q % b == 0) and (r % c == 0) and (p // a == q // b * (r // c) or q // b == p // a * (r // c) or r // c == p // a * (q // b)):
		print('2')
	elif b != 0 and q % b == 0 and (abs(q) >= abs(b)) and (q // b != 0) and (p % (q // b) == 0) and (r % (q // b) == 0) and (p // (q // b) - a == r // (q // b) - c):
		print('2')
	elif a != 0 and p % a == 0 and (abs(p) >= abs(a)) and (p // a != 0) and (q % (p // a) == 0) and (r % (p // a) == 0) and (q // (p // a) - b == r // (p // a) - c):
		print('2')
	elif c != 0 and r % c == 0 and (abs(r) >= abs(c)) and (r // c != 0) and (p % (r // c) == 0) and (q % (r // c) == 0) and (p // (r // c) - a == q // (r // c) - b):
		print('2')
	elif a != 0 and c != 0 and ((p - y) % a == 0) and ((r - y) % c == 0) and ((p - y) // a == (r - y) // c):
		print('2')
	elif b != 0 and c != 0 and ((q - x) % b == 0) and ((r - x) % c == 0) and ((q - x) // b == (r - x) // c):
		print('2')
	elif a != 0 and b != 0 and ((p - z) % a == 0) and ((q - z) % b == 0) and ((p - z) // a == (q - z) // b):
		print('2')
	elif p == 0 and q == r or (q == 0 and p == r) or (r == 0 and p == q):
		print('2')
	elif c != 0 and r % c == 0 and (q - b * (r // c) == p - a * (r // c)) or (b != 0 and q % b == 0 and (r - c * (q // b) == p - a * (q // b))) or (a != 0 and p % a == 0 and (q - b * (p // a) == r - c * (p // a))):
		print('2')
	else:
		if b - a != 0 and (q - p) % (b - a) == 0:
			y = (q - p) // (b - a)
			if (q - p) // (b - a) != 0 and p % y == 0:
				x = p // ((q - p) // (b - a)) - a
				if a + x != 0 and p % (a + x) == 0 and (b + x != 0) and (q % (b + x) == 0) and (c + x != 0) and (r % (c + x) == 0) and (p // (a + x) == 1):
					if q // (b + x) == r // (c + x):
						print('2')
						continue
				elif a + x != 0 and p % (a + x) == 0 and (b + x != 0) and (q % (b + x) == 0) and (c + x != 0) and (r % (c + x) == 0) and (q // (b + x) == 1):
					if p // (a + x) == r // (c + x):
						print('2')
						continue
				elif a + x != 0 and p % (a + x) == 0 and (b + x != 0) and (q % (b + x) == 0) and (c + x != 0) and (r % (c + x) == 0) and (r // (c + x) == 1):
					if p // (a + x) == q // (b + x):
						print('2')
						continue
				elif a + x != 0 and b + x != 0 and (c + x != 0) and (p % (a + x) == 0) and (q % (b + x) == 0) and (r % (c + x) == 0) and (p // (a + x) == q // (b + x)) and (q // (b + x) == r // (c + x)) and (p // (a + x) == r // (c + x)):
					print('2')
					continue
		if c - b != 0 and (r - q) % (c - b) == 0:
			y = (r - q) // (c - b)
			if (r - q) // (c - b) != 0 and q % y == 0:
				x = q // ((r - q) // (c - b)) - b
				if a + x != 0 and p % (a + x) == 0 and (b + x != 0) and (q % (b + x) == 0) and (c + x != 0) and (r % (c + x) == 0) and (p // (a + x) == 1):
					if q // (b + x) == r // (c + x):
						print('2')
						continue
				elif a + x != 0 and p % (a + x) == 0 and (b + x != 0) and (q % (b + x) == 0) and (c + x != 0) and (r % (c + x) == 0) and (q // (b + x) == 1):
					if p // (a + x) == r // (c + x):
						print('2')
						continue
				elif a + x != 0 and p % (a + x) == 0 and (b + x != 0) and (q % (b + x) == 0) and (c + x != 0) and (r % (c + x) == 0) and (r // (c + x) == 1):
					if p // (a + x) == q // (b + x):
						print('2')
						continue
				elif a + x != 0 and p % (a + x) == 0 and (b + x != 0) and (q % (b + x) == 0) and (c + x != 0) and (r % (c + x) == 0) and (p // (a + x) == q // (b + x)) and (q // (b + x) == r // (c + x)) and (p // (a + x) == r // (c + x)):
					print('2')
					continue
		if c - a != 0 and (r - p) % (c - a) == 0:
			y = (r - p) // (c - a)
			if (r - p) // (c - a) != 0 and r % y == 0:
				x = r // ((r - p) // (c - a)) - c
				if a + x != 0 and p % (a + x) == 0 and (b + x != 0) and (q % (b + x) == 0) and (c + x != 0) and (r % (c + x) == 0) and (p // (a + x) == 1):
					if q // (b + x) == r // (c + x):
						print('2')
						continue
				elif a + x != 0 and p % (a + x) == 0 and (b + x != 0) and (q % (b + x) == 0) and (c + x != 0) and (r % (c + x) == 0) and (q // (b + x) == 1):
					if p // (a + x) == r // (c + x):
						print('2')
						continue
				elif a + x != 0 and p % (a + x) == 0 and (b + x != 0) and (q % (b + x) == 0) and (c + x != 0) and (r % (c + x) == 0) and (r // (c + x) == 1):
					if p // (a + x) == q // (b + x):
						print('2')
						continue
				elif a + x != 0 and p % (a + x) == 0 and (b + x != 0) and (q % (b + x) == 0) and (c + x != 0) and (r % (c + x) == 0) and (p // (a + x) == q // (b + x)) and (q // (b + x) == r // (c + x)) and (p // (a + x) == r // (c + x)):
					print('2')
					continue
				else:
					print('3')
					continue
			else:
				print('3')
		else:
			print('3')


def factors(v0, v1, u0, u1):
	den = u0 - v0
	num = u1 - v1
	if den != 0:
		return num // den
	return 1

def solve(p, q, r, a, b, c, num):
	if p == a and q == b and (r == c):
		return num
	if num >= 2:
		return 3
	best = 3
	add_list = [a - p, b - q, c - r]
	mul_list = []
	if p != 0:
		mul_list.append(a // p)
	if q != 0:
		mul_list.append(b // q)
	if r != 0:
		mul_list.append(c // r)
	mul_list.append(factors(p, a, q, b))
	mul_list.append(factors(p, a, r, c))
	mul_list.append(factors(q, b, r, c))
	m = 8
	for i in range(m):
		for add in add_list:
			tp = p
			tq = q
			tr = r
			if i & 1 > 0:
				tp += add
			if i & 2 > 0:
				tq += add
			if i & 4 > 0:
				tr += add
			best = min(best, solve(tp, tq, tr, a, b, c, num + 1))
		for mul in mul_list:
			tp = p
			tq = q
			tr = r
			if i & 1 > 0:
				tp *= mul
			if i & 2 > 0:
				tq *= mul
			if i & 4 > 0:
				tr *= mul
			best = min(best, solve(tp, tq, tr, a, b, c, num + 1))
	return best
for tc in range(int(input())):
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	print(solve(p, q, r, a, b, c, 0))


def get_x(a1, b1, a2, b2):
	x = a2 - a1
	y = b2 - b1
	return y // x if x != 0 and y % x == 0 else 0

def add(t, o, a):
	return tuple(map(lambda x, y: x + a if y else x, t, o))

def mult(t, o, m):
	return tuple(map(lambda x, y: x * m if y else x, t, o))

def solve(s, e, ops=0):
	if s == e:
		return ops
	elif ops >= 2:
		return 3
	res = 3
	diffs = []
	mults = []
	for i in range(3):
		diffs.append(e[i] - s[i])
		if s[i] != 0 and e[i] % s[i] == 0:
			mults.append(e[i] // s[i])
		for j in range(i + 1, 3):
			x = get_x(s[i], e[i], s[j], e[j])
			mults.append(x)
	for i in range(1, 8):
		o = ((4 & i) >> 2, (2 & i) >> 1, 1 & i)
		for d in diffs:
			t = add(s, o, d)
			res = min(res, solve(t, e, ops + 1))
		for m in mults:
			t = mult(s, o, m)
			res = min(res, solve(t, e, ops + 1))
	return res
for t in range(int(input().strip())):
	s = tuple(map(int, input().strip().split()))
	e = tuple(map(int, input().strip().split()))
	print(solve(s, e, 0))


from sys import stdin
from math import gcd
from functools import reduce

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
for _ in range(int(stdin.readline())):
	(p, q, r) = map(int, stdin.readline().split())
	(a, b, c) = map(int, stdin.readline().split())
	if p == a:
		if q == b:
			if r == c:
				print(0)
			else:
				print(1)
		elif r == c:
			print(1)
		elif b - q == c - r or ((q != 0 and r != 0) and (b % q == 0 and c % r == 0) and (b // q == c // r)):
			print(1)
		else:
			print(2)
	elif q == b:
		if r == c:
			print(1)
		elif a - p == c - r or ((p != 0 and r != 0) and (a % p == 0 and c % r == 0) and (a // p == c // r)):
			print(1)
		else:
			print(2)
	elif r == c:
		if a - p == b - q or ((p != 0 and q != 0) and (a % p == 0 and b % q == 0) and (a // p == b // q)):
			print(1)
		else:
			print(2)
	elif a - p == b - q == c - r or ((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)):
		print(1)
	else:
		cond = True
		if a - p == b - q or b - q == c - r or c - r == a - p:
			print(2)
			continue
		if a - p + b - q == c - r or b - q + c - r == a - p or c - r + a - p == b - q:
			print(2)
			continue
		if p != 0 and q != 0 and (a % p == 0) and (b % q == 0) and (a // p == b // q) or (q != 0 and r != 0 and (b % q == 0) and (c % r == 0) and (b // q == c // r)) or (r != 0 and p != 0 and (c % r == 0) and (a % p == 0) and (c // r == a // p)):
			print(2)
			continue
		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):
			print(2)
			continue
		if cond == True:
			k = gcd(a, gcd(b, c))
			arr = factors(k)
			for i in range(1, len(arr)):
				(x, y, z) = (a // arr[i], b // arr[i], c // arr[i])
				if x - p == y - q == z - r:
					cond = False
					break
				(x, y, z) = (a // (0 - arr[i]), b // (0 - arr[i]), c // (0 - arr[i]))
				if x - p == y - q == z - r:
					cond = False
					break
			if cond == False:
				print(2)
				continue
		if cond == True:
			d = c - r
			if (p + d != 0 and q + d != 0) and (a % (p + d) == 0 and b % (q + d) == 0) and (a // (p + d) == b // (q + d)):
				print(2)
				continue
			d = a - p
			if (r + d != 0 and q + d != 0) and (c % (r + d) == 0 and b % (q + d) == 0) and (c // (r + d) == b // (q + d)):
				print(2)
				continue
			d = b - q
			if (p + d != 0 and r + d != 0) and (a % (p + d) == 0 and c % (r + d) == 0) and (a // (p + d) == c // (r + d)):
				print(2)
				continue
		if cond == True:
			if r != 0 and c % r == 0:
				k = c // r
				if k != 0:
					if a % k == 0 and b % k == 0:
						(x, y) = (a // k, b // k)
						if x - p == y - q:
							print(2)
							continue
			if p != 0 and a % p == 0:
				k = a // p
				if k != 0:
					if c % k == 0 and b % k == 0:
						(z, y) = (c // k, b // k)
						if z - r == y - q:
							print(2)
							continue
			if q != 0 and b % q == 0:
				k = b // q
				if k != 0:
					if a % k == 0 and c % k == 0:
						(x, z) = (a // k, c // k)
						if x - p == z - r:
							print(2)
							continue
		if cond == True:
			if r != 0 and c % r == 0:
				k = c // r
				if k != 0:
					if a % k == 0 and a // k - p == b - q or (b % k == 0 and b // k - q == a - p):
						print(2)
						continue
			if p != 0 and a % p == 0:
				k = a // p
				if k != 0:
					if c % k == 0 and c // k - r == b - q or (b % k == 0 and b // k - q == c - r):
						print(2)
						continue
			if q != 0 and b % q == 0:
				k = b // q
				if k != 0:
					if a % k == 0 and a // k - p == c - r or (c % k == 0 and c // k - r == a - p):
						print(2)
						continue
		if (p != q and q != r and (p != r)) and ((a - b) % (p - q) == 0 and (a - c) % (p - r) == 0 and ((c - b) % (r - q) == 0)) and ((a - b) // (p - q) == (a - c) // (p - r) == (c - b) // (r - q)):
			print(2)
			continue
		if r != 0 and c % r == 0:
			k = c // r
			if k != 0:
				if a - p * k == b - q * k:
					print(2)
					continue
		if p != 0 and a % p == 0:
			k = a // p
			if k != 0:
				if c - r * k == b - q * k:
					print(2)
					continue
		if q != 0 and b % q == 0:
			k = b // q
			if k != 0:
				if a - p * k == c - r * k:
					print(2)
					continue
		if cond == True:
			d = c - r
			if p != 0 and q != 0:
				if (a - d) % p == 0 and (b - d) % q == 0 and ((a - d) // p == (b - d) // q):
					print(2)
					continue
			d = a - p
			if r != 0 and q != 0:
				if (c - d) % r == 0 and (b - d) % q == 0 and ((c - d) // r == (b - d) // q):
					print(2)
					continue
			d = b - q
			if p != 0 and r != 0:
				if (a - d) % p == 0 and (c - d) % r == 0 and ((a - d) // p == (c - d) // r):
					print(2)
					continue
		if cond == True:
			d = c - r
			if p != 0 and q != 0 and ((b - d) % q == 0) and (a % p == 0) and ((b - d) // q == a // p):
				print(2)
				continue
			if p != 0 and q != 0 and ((a - d) % p == 0) and (b % q == 0) and ((a - d) // p == b // q):
				print(2)
				continue
			d = a - p
			if r != 0 and q != 0 and ((b - d) % q == 0) and (c % r == 0) and ((b - d) // q == c // r):
				print(2)
				continue
			if r != 0 and q != 0 and ((c - d) % r == 0) and (b % q == 0) and ((c - d) // r == b // q):
				print(2)
				continue
			d = b - q
			if p != 0 and r != 0 and ((c - d) % r == 0) and (a % p == 0) and ((c - d) // r == a // p):
				print(2)
				continue
			if p != 0 and r != 0 and ((a - d) % p == 0) and (c % r == 0) and ((a - d) // p == c // r):
				print(2)
				continue
		if cond == True:
			if a == b == c == 0:
				print(1)
				continue
			if a == b == c:
				print(2)
				continue
			if a == b == 0 or b == c == 0 or a == c == 0:
				print(2)
				continue
			if a == 0 and b == c or (b == 0 and a == c) or (c == 0 and b == a):
				print(2)
				continue
		print(3)


def solve(a, b, operations):
	if a == b:
		return operations
	if operations >= 2:
		return 3
	ops = 3
	add_set = [b[0] - a[0], b[1] - a[1], b[2] - a[2]]
	mult_set = []
	for i in range(3):
		if a[i] != 0:
			mult_set.append(b[i] // a[i])
	if a[1] - a[0] != 0:
		mult_set.append((b[1] - b[0]) // (a[1] - a[0]))
	if a[2] - a[0] != 0:
		mult_set.append((b[2] - b[0]) // (a[2] - a[0]))
	if a[2] - a[1] != 0:
		mult_set.append((b[2] - b[1]) // (a[2] - a[1]))
	for x in range(8):
		for i in add_set:
			s = [int(i) for i in a]
			if x & 1 > 0:
				s[0] += i
			if x & 2 > 0:
				s[1] += i
			if x & 4 > 0:
				s[2] += i
			ops = min(ops, solve(s, b, operations + 1))
		for i in mult_set:
			s = [int(i) for i in a]
			if x & 1 > 0:
				s[0] *= i
			if x & 2 > 0:
				s[1] *= i
			if x & 4 > 0:
				s[2] *= i
			ops = min(ops, solve(s, b, operations + 1))
	return ops
for t in range(int(input().strip())):
	a = [int(i) for i in input().strip().split()]
	b = [int(i) for i in input().strip().split()]
	print(solve(a, b, 0))


def findanswer2(p, q, r, a, b, c):
	temp = 1
	add = p * b - a * q
	if p - q == 0 or add % (p - q) != 0:
		return 0
	add //= p - q
	sub = a - add
	if p == 0 or sub % p != 0:
		return 0
	sub //= p
	p1 = p
	q1 = q
	r1 = r
	r += add
	if r == c:
		temp += 1
		return temp
	p = p1
	q = q1
	r = r1
	r *= sub
	if r == c:
		temp += 1
		return temp
	p = p1
	q = q1
	r = r1
	r = r * sub + add
	if r == c:
		temp += 1
		return temp
	p = p1
	q = q1
	r = r1
	sub = a - b
	if p - q == 0 or sub % (p - q) != 0:
		return 0
	sub //= p - q
	add = a
	if sub == 0 or add % sub != 0:
		return 0
	add //= sub
	add -= p
	r += add
	if r == c:
		temp += 1
		return temp
	p = p1
	q = q1
	r = r1
	r *= sub
	if r == c:
		temp += 1
		return temp
	p = p1
	q = q1
	r = r1
	r = (r + add) * sub
	if r == c:
		temp += 1
		return temp
	return 0

def findanswer(p, q, r, a, b, c):
	temp = 1
	diff = c - r
	if a == 0 and b == 0:
		temp += 1
		return temp
	if p - a == q - b:
		temp += 1
		return temp
	if p != 0 and a % p == 0 and (q != 0) and (b % q == 0):
		if a // p == b // q:
			temp += 1
			return temp
	p1 = p
	q1 = q
	r1 = r
	p += diff
	if p - a == q - b:
		temp += 1
		return temp
	if p != 0 and a % p == 0 and (q != 0) and (b % q == 0):
		if a // p == b // q:
			temp += 1
			return temp
	p = p1
	q = q1
	r = r1
	q += diff
	if p - a == q - b:
		temp += 1
		return temp
	if p != 0 and a % p == 0 and (q != 0) and (b % q == 0):
		if a // p == b // q:
			temp += 1
			return temp
	p = p1
	q = q1
	r = r1
	p += diff
	q += diff
	if p - a == q - b:
		temp += 1
		return temp
	if p != 0 and a % p == 0 and (q != 0) and (b % q == 0):
		if a // p == b // q:
			temp += 1
			return temp
	p = p1
	q = q1
	r = r1
	if r != 0 and c % r == 0:
		mult = c // r
		if p - a == q - b:
			temp += 1
			return temp
		if p != 0 and a % p == 0 and (q != 0) and (b % q == 0):
			if a // p == b // q:
				temp += 1
				return temp
		p = p1
		q = q1
		r = r1
		p *= mult
		if p - a == q - b:
			temp += 1
			return temp
		if p != 0 and a % p == 0 and (q != 0) and (b % q == 0):
			if a // p == b // q:
				temp += 1
				return temp
		p = p1
		q = q1
		r = r1
		q *= mult
		if p - a == q - b:
			temp += 1
			return temp
		if p != 0 and a % p == 0 and (q != 0) and (b % q == 0):
			if a // p == b // q:
				temp += 1
				return temp
		p = p1
		q = q1
		r = r1
		p *= mult
		q *= mult
		if p - a == q - b:
			temp += 1
			return temp
		if p != 0 and a % p == 0 and (q != 0) and (b % q == 0):
			if a // p == b // q:
				temp += 1
				return temp
	return 0

def sol():
	(p, q, r) = input().split()
	(a, b, c) = input().split()
	p = int(p)
	q = int(q)
	r = int(r)
	a = int(a)
	b = int(b)
	c = int(c)
	if p == a and q == b and (r == c):
		count = 0
		print(count)
		return
	if a == 0 and b == 0 and (c == 0):
		count = 1
		print(count)
		return
	if p - a == q - b and q - b == r - c:
		count = 1
		print(count)
		return
	if p != 0 and a % p == 0 and (q != 0) and (b % q == 0) and (r != 0) and (c % r == 0):
		if a // p == b // q and b // q == c // r:
			count = 1
			print(count)
			return
	if p != a and q == b and (r == c) or (p == a and q != b and (r == c)) or (p == a and q == b and (r != c)):
		count = 1
		print(count)
		return
	if p != a and q != b and (r == c):
		if a == 0 and b == 0:
			count = 1
			print(count)
			return
		if p - a == q - b:
			count = 1
			print(count)
			return
		if p != 0 and a % p == 0 and (q != 0) and (b % q == 0):
			if a // p == b // q:
				count = 1
				print(count)
				return
		count = 2
		print(count)
		return
	if p != a and q == b and (r != c):
		if a == 0 and c == 0:
			count = 1
			print(count)
			return
		if p - a == r - c:
			count = 1
			print(count)
			return
		if p != 0 and a % p == 0 and (r != 0) and (c % r == 0):
			if a // p == c // r:
				count = 1
				print(count)
				return
		count = 2
		print(count)
		return
	if p == a and q != b and (r != c):
		if b == 0 and c == 0:
			count = 1
			print(count)
			return
		if q - b == r - c:
			count = 1
			print(count)
			return
		if q != 0 and b % q == 0 and (r != 0) and (c % r == 0):
			if b // q == c // r:
				count = 1
				print(count)
				return
		count = 2
		print(count)
		return
	answer = 0
	answer = findanswer(p, q, r, a, b, c)
	if answer == 2:
		count = 2
		print(count)
		return
	answer = findanswer(p, r, q, a, c, b)
	if answer == 2:
		count = 2
		print(count)
		return
	answer = findanswer(q, r, p, b, c, a)
	if answer == 2:
		count = 2
		print(count)
		return
	answer = findanswer2(p, q, r, a, b, c)
	if answer == 2:
		count = 2
		print(count)
		return
	answer = findanswer2(p, r, q, a, c, b)
	if answer == 2:
		count = 2
		print(count)
		return
	answer = findanswer2(q, r, p, b, c, a)
	if answer == 2:
		count = 2
		print(count)
		return
	count = 3
	print(count)
T = int(input())
for i in range(T):
	sol()


global aa, bb, cc, xx, yy, zz

def isZero(a, b, c, x, y, z):
	return a == x and b == y and (c == z)

def isIT(a, b, c, x, y, z, d):
	if isZero(a * d, b, c, x, y, z):
		return True
	if isZero(a, b * d, c, x, y, z):
		return True
	if isZero(a, b, c * d, x, y, z):
		return True
	if isZero(a * d, b * d, c, x, y, z):
		return True
	if isZero(a * d, b, c * d, x, y, z):
		return True
	if isZero(a * d, b * d, c * d, x, y, z):
		return True
	if isZero(a, b * d, c * d, x, y, z):
		return True
	return False

def isOne(a, b, c, x, y, z):
	if a != 0:
		if isIT(a, b, c, x, y, z, x // a):
			return True
	if b != 0:
		if isIT(a, b, c, x, y, z, y // b):
			return True
	if c != 0:
		if isIT(a, b, c, x, y, z, z // c):
			return True
	l = [0, 0, 0]
	l[0] = x - a
	l[1] = y - b
	l[2] = z - c
	if l[0] == l[1] and l[1] == l[2] or (l[0] == l[1] and (l[2] == 0 if l[0] != 0 else True)) or (l[0] == l[2] and (l[1] == 0 if l[0] != 0 else True)) or (l[1] == l[2] and (l[0] == 0 if l[1] != 0 else True)):
		return True
	return False

def difSum(a, b, c, x, y, z):
	l = [x - a, y - b, z - c]
	for i in range(3):
		d = l[i]
		if isOne(a + d, b, c, x, y, z):
			return True
		if isOne(a + d, b + d, c, x, y, z):
			return True
		if isOne(a + d, b, c + d, x, y, z):
			return True
		if isOne(a + d, b + d, c + d, x, y, z):
			return True
		if isOne(a, b + d, c + d, x, y, z):
			return True
		if isOne(a, b + d, c, x, y, z):
			return True
		if isOne(a, b, c + d, x, y, z):
			return True
	return False

def difMul(a, b, c, x, y, z):
	l = [x // a if a != 0 else 0, y // b if b != 0 else 0, z // c if c != 0 else 0, 0]
	for i in range(4):
		d = l[i]
		if isOne(a * d, b, c, x, y, z):
			return True
		if isOne(a * d, b * d, c, x, y, z):
			return True
		if isOne(a * d, b, c * d, x, y, z):
			return True
		if isOne(a * d, b * d, c * d, x, y, z):
			return True
		if isOne(a, b * d, c * d, x, y, z):
			return True
		if isOne(a, b * d, c, x, y, z):
			return True
		if isOne(a, b, c * d, x, y, z):
			return True
	return False

def mulSum(a, b, c, x, y, z):
	if a - b != 0:
		if (x - y) % (a - b) != 0:
			return False
		X = (x - y) // (a - b)
		Y = x - a * X
		if c * X + Y == z or c * X == z or c + Y == z:
			return True
	if b - a != 0:
		if (y - x) % (b - a) != 0:
			return False
		X = (y - x) // (b - a)
		Y = x - a * X
		if c * X + Y == z or c * X == z or c + Y == z:
			return True
	return False

def difMulSum(a, b, c, x, y, z):
	if mulSum(a, b, c, x, y, z):
		return True
	if mulSum(a, c, b, x, z, y):
		return True
	if mulSum(b, c, a, y, z, x):
		return True
	return False

def isTwo(a, b, c, x, y, z):
	if x == a or y == b or z == c:
		return True
	if difSum(aa, bb, cc, xx, yy, zz):
		return True
	if difMul(aa, bb, cc, xx, yy, zz):
		return True
	if difMulSum(aa, bb, cc, xx, yy, zz):
		return True
	return False
T = int(input())
for _ in range(T):
	(aa, bb, cc) = map(int, input().split())
	(xx, yy, zz) = map(int, input().split())
	if isZero(aa, bb, cc, xx, yy, zz):
		print(0)
	elif isOne(aa, bb, cc, xx, yy, zz):
		print(1)
	elif isTwo(aa, bb, cc, xx, yy, zz):
		print(2)
	else:
		print(3)


import math

def check_int(x):
	return math.floor(x) == x

def check_split_prod(initial, target):
	pairs = [(0, 1, 2), (1, 2, 0), (2, 0, 1)]
	ans = 0
	for pair in pairs:
		init = initial[pair[-1]]
		fin = target[pair[-1]]
		prod1 = divide(target[pair[0]], initial[pair[0]])
		prod2 = divide(target[pair[1]], initial[pair[1]])
		diff1 = target[pair[0]] - initial[pair[0]]
		diff2 = target[pair[1]] - initial[pair[1]]
		if prod1 != None:
			ans = ans or prod1 * init + diff2 == fin
			ans = ans or prod1 * (init + diff2) == fin
		if prod2 != None:
			ans = ans or prod2 * init + diff1 == fin
			ans = ans or prod2 * (init + diff1) == fin
		if prod1 != None and prod2 != None:
			ans = ans or prod1 * prod2 * init == fin
		ans = ans or diff1 + diff2 + init == fin
		ans = ans or (initial[pair[0]] == initial[pair[1]] and target[pair[0]] == target[pair[1]])
	return bool(ans)

def find_m_and_C(x1, y1, x2, y2):
	if x2 == x1:
		return (None, None)
	div = divmod(y2 - y1, x2 - x1)
	if div[1] != 0:
		return (None, None)
	m = div[0]
	C = y1 - m * x1
	return (m, C)

def divide(a, b):
	if b == 0:
		return None
	div = divmod(a, b)
	if div[1] != 0:
		return None
	return div[0]

def pentuple_list(initial, target):
	pairs = [(0, 1, 2), (1, 2, 0), (2, 0, 1)]
	q_list = []
	for pair in pairs:
		(m, C) = find_m_and_C(initial[pair[0]], target[pair[0]], initial[pair[1]], target[pair[1]])
		if m == None:
			continue
		q_list.append((m, C, divide(C, m), divide(target[pair[-1]], initial[pair[-1]]), target[pair[-1]] - initial[pair[-1]]))
	return q_list
T = int(input())
for t in range(T):
	(p, q, r) = initial = [int(i) for i in input().split()]
	(a, b, c) = target = [int(i) for i in input().split()]
	equality_list = [int(target[i] == initial[i]) for i in range(3)]
	if sum(equality_list) == 3:
		ans = 0
	elif sum(equality_list) == 2:
		ans = 1
	elif sum(equality_list) == 1:
		(ind1, ind2) = [i for i in range(3) if not equality_list[i]]
		if initial[ind1] - target[ind1] == initial[ind2] - target[ind2] or (initial[ind1] * initial[ind2] != 0 and target[ind2] // initial[ind2] == target[ind1] // initial[ind1] and (divide(target[ind1], initial[ind1]) and divide(target[ind2], initial[ind2]))):
			ans = 1
		else:
			ans = 2
	elif initial[0] - target[0] == initial[1] - target[1] == initial[2] - target[2] or (initial[0] * initial[1] * initial[2] != 0 and target[0] // initial[0] == target[1] // initial[1] == target[2] // initial[2] and (divide(target[0], initial[0]) != None and divide(target[1], initial[1]) != None and (divide(target[2], initial[2]) != None))):
		ans = 1
	else:
		ans = 3
		q_list = pentuple_list(initial, target)
		if len(q_list) == 3:
			if q_list[0][0] == q_list[1][0] == q_list[2][0] and q_list[0][1] == q_list[1][1] == q_list[2][1]:
				ans = 2
		for q in q_list:
			if q[0] == q[3] or q[1] == q[4] or q[2] == q[4] or (q[0] == 1) or (q[1] == 0):
				ans = 2
		if check_split_prod(initial, target):
			ans = 2
	print(ans)


def case_0(a1, b1, c1, a2, b2, c2):
	if a1 == a2 and b1 == b2 and (c1 == c2):
		return True
	return False

def case_1(a1, b1, c1, a2, b2, c2):
	if a2 == a1 and b2 == b1 or (c2 == c1 and b2 == b1) or (a2 == a1 and c2 == c1):
		return True
	elif a2 == 0 and b2 == 0 and (c2 == 0):
		return True
	elif a2 - a1 == b2 - b1 == c2 - c1:
		return True
	elif (b1 != 0 and b2 % b1 == 0) and (c1 != 0 and c2 % c1 == 0) and (a1 != 0 and a2 % a1 == 0) and (b2 // b1 == c2 // c1 == a2 // a1):
		return True
	elif a2 == a1 and (b2 - b1 == c2 - c1 or ((b1 != 0 and b2 % b1 == 0) and (c1 != 0 and c2 % c1 == 0) and (b2 * c1 == c2 * b1))):
		return True
	elif b2 == b1 and (a2 - a1 == c2 - c1 or ((a1 != 0 and a2 % a1 == 0) and (c1 != 0 and c2 % c1 == 0) and (a2 * c1 == c2 * a1))):
		return True
	elif c2 == c1 and (b2 - b1 == a2 - a1 or ((b1 != 0 and b2 % b1 == 0) and (a1 != 0 and a2 % a1 == 0) and (b2 * a1 == a2 * b1))):
		return True
	return False

def case_2(a1, b1, c1, a2, b2, c2):
	if a1 == a2 or b1 == b2 or c1 == c2:
		return True
	if a2 - a1 == b2 - b1 or b2 - b1 == c2 - c1 or c2 - c1 == a2 - a1:
		return True
	if (b1 != 0 and b2 % b1 == 0) and (c1 != 0 and c2 % c1 == 0) and (b2 * c1 == c2 * b1) or ((a1 != 0 and a2 % a1 == 0) and (c1 != 0 and c2 % c1 == 0) and (a2 * c1 == c2 * a1)) or ((b1 != 0 and b2 % b1 == 0) and (a1 != 0 and a2 % a1 == 0) and (b2 * a1 == a2 * b1)):
		return True
	if a2 == b2 == 0 or a2 == c2 == 0 or b2 == c2 == 0:
		return True
	if b1 != 0 and b2 % b1 == 0 and (b2 // b1 != 0) and (a1 != 0) and (a2 % (a1 * (b2 // b1)) == 0):
		d1 = b2 // b1
		d2 = a2 // (a1 * d1)
		if c1 * d1 == c2 or c1 * d1 * d2 == c2 or c1 * d2 == c2:
			return True
	if a1 != 0 and a2 % a1 == 0 and (a2 // a1 != 0) and (b1 != 0) and (b2 % (b1 * (a2 // a1)) == 0):
		d1 = a2 // a1
		d2 = b2 // (b1 * d1)
		if c1 * d1 == c2 or c1 * d1 * d2 == c2 or c1 * d2 == c2:
			return True
	if c1 != 0 and c2 % c1 == 0 and (c2 // c1 != 0) and (a1 != 0) and (a2 % (a1 * (c2 // c1)) == 0):
		d1 = c2 // c1
		d2 = a2 // (a1 * d1)
		if b1 * d1 == b2 or c1 * d1 * d2 == b2 or b1 * d2 == b2:
			return True
	if a1 != 0 and a2 % a1 == 0 and (a2 // a1 != 0) and (c1 != 0) and (c2 % (c1 * (a2 // a1)) == 0):
		d1 = a2 // a1
		d2 = c2 // (c1 * d1)
		if b1 * d1 == b2 or b1 * d1 * d2 == b2 or b1 * d2 == b2:
			return True
	if c1 != 0 and c2 % c1 == 0 and (c2 // c1 != 0) and (b1 != 0) and (b2 % (b1 * (c2 // c1)) == 0):
		d1 = c2 // c1
		d2 = b2 // (b1 * d1)
		if a1 * d1 == a2 or a1 * d1 * d2 == a2 or a1 * d2 == a2:
			return True
	if b1 != 0 and b2 % b1 == 0 and (b2 // b1 != 0) and (c1 != 0) and (c2 % (c1 * (b2 // b1)) == 0):
		d1 = b2 // b1
		d2 = c2 // (c1 * d1)
		if a1 * d1 == a2 or a1 * d1 * d2 == a2 or a1 * d2 == a2:
			return True
	if a1 + (b2 - b1) + (c2 - c1) == a2:
		return True
	if b1 + (a2 - a1) + (c2 - c1) == b2:
		return True
	if c1 + (a2 - a1) + (b2 - b1) == c2:
		return True
	if b1 != a1 and (b2 - a2) % (b1 - a1) == 0:
		d2 = (b2 - a2) // (b1 - a1)
		if d2 != 0 and a2 % d2 == 0:
			d1 = a2 // d2 - a1
			if (c1 + d1) * d2 == c2 or c1 * d2 == c2 or c1 + d1 == c2:
				return True
	if c1 != a1 and (c2 - a2) % (c1 - a1) == 0:
		d2 = (c2 - a2) // (c1 - a1)
		if d2 != 0 and a2 % d2 == 0:
			d1 = a2 // d2 - a1
			if (b1 + d1) * d2 == b2 or b1 * d2 == b2 or b1 + d1 == b2:
				return True
	if c1 != b1 and (c2 - b2) % (c1 - b1) == 0:
		d2 = (c2 - b2) // (c1 - b1)
		if d2 != 0 and b2 % d2 == 0:
			d1 = b2 // d2 - b1
			if (a1 + d1) * d2 == a2 or a1 * d2 == a2 or a1 + d1 == a2:
				return True
	if a1 + b2 != b1 and a2 % (a1 + b2 - b1) == 0:
		d1 = b2 - b1
		d2 = a2 // (a1 + d1)
		if c1 + d1 == c2 or c1 * d2 == c2:
			return True
	if a1 + c2 != c1 and a2 % (a1 + c2 - c1) == 0:
		d1 = c2 - c1
		d2 = a2 // (a1 + d1)
		if b1 + d1 == b2 or b1 * d2 == b2:
			return True
	if c1 + b2 != b1 and c2 % (c1 + b2 - b1) == 0:
		d1 = b2 - b1
		d2 = c2 // (c1 + d1)
		if a1 + d1 == a2 or a1 * d2 == a2:
			return True
	if c1 + a2 != a1 and c2 % (c1 + a2 - a1) == 0:
		d1 = a2 - a1
		d2 = c2 // (c1 + d1)
		if b1 + d1 == b2 or b1 * d2 == b2:
			return True
	if b1 + c2 != c1 and b2 % (b1 + c2 - c1) == 0:
		d1 = c2 - c1
		d2 = b2 // (b1 + d1)
		if a1 + d1 == a2 or a1 * d2 == a2:
			return True
	if b1 + a2 != a1 and b2 % (b1 + a2 - a1) == 0:
		d1 = a2 - a1
		d2 = b2 // (b1 + d1)
		if c1 + d1 == c2 or c1 * d2 == c2:
			return True
	if b1 != 0 and b2 != 0 and (b2 % b1 == 0) and (a2 % (b2 // b1) == 0):
		d2 = b2 // b1
		d1 = a2 * b1 // b2 - a1
		if c1 * d2 == c2 or c1 + d1 == c2:
			return True
	if b1 != 0 and b2 != 0 and (b2 % b1 == 0) and (c2 % (b2 // b1) == 0):
		d2 = b2 // b1
		d1 = c2 * b1 // b2 - c1
		if a1 * d2 == a2 or a1 + d1 == a2:
			return True
	if c1 != 0 and c2 != 0 and (c2 % c1 == 0) and (a2 % (c2 // c1) == 0):
		d2 = c2 // c1
		d1 = a2 * c1 // c2 - a1
		if b1 * d2 == b2 or b1 + d1 == b2:
			return True
	if c1 != 0 and c2 != 0 and (c2 % c1 == 0) and (b2 % (c2 // c1) == 0):
		d2 = c2 // c1
		d1 = b2 * c1 // c2 - b1
		if a1 * d2 == a2 or a1 + d1 == a2:
			return True
	if a1 != 0 and a2 != 0 and (a2 % a1 == 0) and (b2 % (a2 // a1) == 0):
		d2 = a2 // a1
		d1 = b2 * a1 // a2 - b1
		if c1 * d2 == c2 or c1 + d1 == c2:
			return True
	if a1 != 0 and a2 != 0 and (a2 % a1 == 0) and (c2 % (a2 // a1) == 0):
		d2 = a2 // a1
		d1 = c2 * a1 // a2 - c1
		if b1 * d2 == b2 or b1 + d1 == b2:
			return True
	if b1 != a1 and (b2 - a2) % (b1 - a1) == 0:
		d1 = (b2 - a2) // (b1 - a1)
		d2 = a2 - a1 * d1
		if c1 * d1 + d2 == c2 or c1 + d2 == c2 or c1 * d1 == c2:
			return True
	if c1 != a1 and (c2 - a2) % (c1 - a1) == 0:
		d1 = (c2 - a2) // (c1 - a1)
		d2 = a2 - a1 * d1
		if b1 * d1 + d2 == b2 or b1 + d2 == b2 or b1 * d1 == b2:
			return True
	if b1 != c1 and (b2 - c2) % (b1 - c1) == 0:
		d1 = (b2 - c2) // (b1 - c1)
		d2 = c2 - c1 * d1
		if a1 * d1 + d2 == a2 or a1 + d2 == a2 or a1 * d1 == a2:
			return True
	if a1 != 0 and (a2 - (b2 - b1)) % a1 == 0:
		d2 = b2 - b1
		d1 = (a2 - d2) // a1
		if c1 + d2 == c2 or c1 * d1 == c2:
			return True
	if a1 != 0 and (a2 - (c2 - c1)) % a1 == 0:
		d2 = c2 - c1
		d1 = (a2 - d2) // a1
		if b1 + d2 == b2 or b1 * d1 == b2:
			return True
	if c1 != 0 and (c2 - (b2 - b1)) % c1 == 0:
		d2 = b2 - b1
		d1 = (c2 - d2) // c1
		if a1 + d2 == a2 or a1 * d1 == a2:
			return True
	if c1 != 0 and (c2 - (a2 - a1)) % c1 == 0:
		d2 = a2 - a1
		d1 = (c2 - d2) // c1
		if b1 + d2 == b2 or b1 * d1 == b2:
			return True
	if b1 != 0 and (b2 - (a2 - a1)) % b1 == 0:
		d2 = a2 - a1
		d1 = (b2 - d2) // b1
		if c1 + d2 == c2 or c1 * d1 == c2:
			return True
	if b1 != 0 and (b2 - (c2 - c1)) % b1 == 0:
		d2 = c2 - c1
		d1 = (b2 - d2) // b1
		if a1 + d2 == a2 or a1 * d1 == a2:
			return True
	if b1 != 0 and b2 % b1 == 0:
		d1 = b2 // b1
		d2 = a2 - a1 * d1
		if c1 + d2 == c2 or c1 * d1 == c2:
			return True
	if b1 != 0 and b2 % b1 == 0:
		d1 = b2 // b1
		d2 = c2 - c1 * d1
		if a1 + d2 == a2 or a1 * d1 == a2:
			return True
	if c1 != 0 and c2 % c1 == 0:
		d1 = c2 // c1
		d2 = a2 - a1 * d1
		if b1 + d2 == b2 or b1 * d1 == b2:
			return True
	if c1 != 0 and c2 % c1 == 0:
		d1 = c2 // c1
		d2 = b2 - b1 * d1
		if a1 + d2 == a2 or a1 * d1 == a2:
			return True
	if a1 != 0 and a2 % a1 == 0:
		d1 = a2 // a1
		d2 = c2 - c1 * d1
		if b1 + d2 == b2 or b1 * d1 == b2:
			return True
	if a1 != 0 and a2 % a1 == 0:
		d1 = a2 // a1
		d2 = b2 - b1 * d1
		if c1 + d2 == c2 or c1 * d1 == c2:
			return True
	return False
T = int(input())
for _ in range(T):
	line = input().split()
	a1 = int(line[0])
	b1 = int(line[1])
	c1 = int(line[2])
	line = input().split()
	a2 = int(line[0])
	b2 = int(line[1])
	c2 = int(line[2])
	case0 = case_0(a1, b1, c1, a2, b2, c2)
	case1 = False
	case2 = False
	if not case0:
		case1 = case_1(a1, b1, c1, a2, b2, c2)
	if not case1:
		case2 = case_2(a1, b1, c1, a2, b2, c2)
	if case0:
		print(0)
	elif case1:
		print(1)
	elif case2:
		print(2)
	else:
		print(3)


def checkzero(a, b, c, p, q, r):
	if a == p and b == q and (c == r):
		return True
	return False

def checkone(a, b, c, p, q, r):
	diff = p - a
	if checkzero(a + diff, b, c, p, q, r) or checkzero(a + diff, b + diff, c, p, q, r) or checkzero(a + diff, b, c + diff, p, q, r) or checkzero(a + diff, b + diff, c + diff, p, q, r):
		return True
	if a != 0 and p % a == 0:
		diff = p // a
		if checkzero(a * diff, b, c, p, q, r) or checkzero(a * diff, b * diff, c, p, q, r) or checkzero(a * diff, b, c * diff, p, q, r) or checkzero(a * diff, b * diff, c * diff, p, q, r):
			return True
	return False

def check1(a, b, c, p, q, r):
	if checkone(a, b, c, p, q, r) or checkone(b, c, a, q, r, p) or checkone(c, a, b, r, p, q):
		return True
	return False

def checktwo(a, b, c, p, q, r):
	diff = p - a
	if check1(a + diff, b, c, p, q, r) or check1(a + diff, b + diff, c, p, q, r) or check1(a + diff, b, c + diff, p, q, r) or check1(a + diff, b + diff, c + diff, p, q, r):
		return True
	if a != 0:
		diff = p // a
		if check1(a * diff, b, c, p, q, r) or check1(a * diff, b * diff, c, p, q, r) or check1(a * diff, b, c * diff, p, q, r) or check1(a * diff, b * diff, c * diff, p, q, r):
			return True
	return False

def check2(a, b, c, p, q, r):
	if checktwo(a, b, c, p, q, r) or checktwo(b, c, a, q, r, p) or checktwo(c, a, b, r, p, q):
		return True
	return False

def newchecktwo(a, b, c, p, q, r):
	if a - b != 0:
		k = (p - q) / (a - b)
		x = (a * q - p * b) / (a - b)
		if k % 1 == 0 and x % 1 == 0:
			if checkzero(a * k + x, b * k + x, c * k, p, q, r) or checkzero(a * k + x, b * k + x, c * k + x, p, q, r) or checkzero(a * k + x, b * k + x, c + x, p, q, r):
				return True
	return False

def newcheck2(a, b, c, p, q, r):
	if newchecktwo(a, b, c, p, q, r) or newchecktwo(b, c, a, q, r, p) or newchecktwo(c, a, b, r, p, q):
		return True
	return False
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	(p, q, r) = map(int, input().split())
	for o in range(45):
		break
	if checkzero(a, b, c, p, q, r):
		print(0)
		continue
	for o in range(45):
		break
	if check1(a, b, c, p, q, r):
		print(1)
		continue
	if check2(a, b, c, p, q, r):
		print(2)
		continue
	if newcheck2(a, b, c, p, q, r):
		print(2)
		continue
	print(3)


temp = 2 ** 32

def fun1(f, aux, x1, j1, x2, j2):
	if (f + x1) * j1 == aux:
		return 1
	elif f * j2 + x2 == aux:
		return 1
	elif (f + x2) * j2 == aux:
		return 1
	elif f * j1 + x1 == aux:
		return 1
	else:
		return 0

def fun2(p, q, r, a, b, c):
	difference = c - r
	p1 = a - difference
	q1 = b - difference
	if p != 0 and q != 0:
		j1 = p1 / p
		j2 = q1 / q
		if j1 == j2 and j1 == p1 // p:
			return 1
	p1 = p + difference
	q1 = q + difference
	if p1 != 0 and q1 != 0:
		j1 = a / p1
		j2 = b / q1
		if j1 == j2 and j1 == a // p1:
			return 1
	return 0

def fun3(p, q, r, a, b, c):
	if r == 0:
		return 0
	m = c / r
	if m != c // r:
		return 0
	p1 = p * m
	q1 = q * m
	if a - p1 == b - q1:
		return 1
	if m == 0:
		return 0
	p1 = a / m
	q1 = b / m
	if p1 - p == q1 - q and p1 - p == int(p1 - p):
		return 1
	return 0

def fun4(p, q, r, a, b, c):
	if p == q:
		return 0
	val = (a - b) / (p - q)
	if val != (a - b) // (p - q) or val == 0:
		return 0
	d1 = a / val - p
	d2 = b / val - q
	d3 = c / val - r
	if d1 == d2 and d2 == d3 and (d1 == int(d1)):
		return 1
	d1 = a - p * val
	d2 = b - q * val
	d3 = c - r * val
	if d1 == d2 and d2 == d3 and (d1 == int(d1)):
		return 1
	return 0
testcases = int(input())
for i in range(testcases):
	h = list(map(int, input().split()))
	p = h[0]
	q = h[1]
	r = h[2]
	u = list(map(int, input().split()))
	a = u[0]
	b = u[1]
	c = u[2]
	d = []
	m = []
	d.append(a - p)
	d.append(b - q)
	d.append(c - r)
	if p != 0 and a % p == 0:
		m.append(a / p)
	else:
		m.append(temp)
	if q != 0 and b % q == 0:
		m.append(b / q)
	else:
		m.append(temp)
	if r != 0 and c % r == 0:
		m.append(c / r)
	else:
		m.append(temp)
	if a == p and b == q and (c == r):
		print(0)
	elif d[0] == d[1] and d[1] == d[2]:
		print(1)
	elif m[0] == m[1] and m[1] == m[2] and (m[0] != temp):
		print(1)
	elif d[0] == 0 and d[1] == 0 or (d[1] == 0 and d[2] == 0) or (d[0] == 0 and d[2] == 0):
		print(1)
	elif d[0] == 0:
		if d[1] == d[2]:
			print(1)
		elif m[1] == m[2] and m[1] != temp:
			print(1)
		else:
			print(2)
	elif d[1] == 0:
		if d[0] == d[2] or (m[0] == m[2] and m[0] != temp):
			print(1)
		else:
			print(2)
	elif d[2] == 0:
		if d[1] == d[0] or (m[1] == m[0] and m[0] != temp):
			print(1)
		else:
			print(2)
	elif fun1(p, a, d[1], m[2], d[2], m[1]) or fun1(q, b, d[0], m[2], d[2], m[0]) or fun1(r, c, d[0], m[1], d[1], m[0]):
		print(2)
	elif fun2(p, q, r, a, b, c) or fun2(q, r, p, b, c, a) or fun2(r, p, q, c, a, b):
		print(2)
	elif fun3(p, q, r, a, b, c) or fun3(q, r, p, b, c, a) or fun3(r, p, q, c, a, b):
		print(2)
	elif fun4(p, q, r, a, b, c):
		print(2)
	elif d[0] == d[1] + d[2] or d[1] == d[0] + d[2] or d[2] == d[1] + d[0]:
		print(2)
	elif m[0] == m[1] * m[2] or m[1] == m[2] * m[0] or m[2] == m[0] * m[1]:
		print(2)
	elif d[1] == d[2] or (m[1] == m[2] and m[1] != temp):
		print(2)
	elif d[0] == d[2] or (m[0] == m[2] and m[0] != temp):
		print(2)
	elif d[0] == d[1] or (m[0] == m[1] and m[0] != temp):
		print(2)
	else:
		print(3)


def gOP(X):
	(ad, md, Y, t) = ([], [], [], 0)
	for (i, j) in X:
		if i != j:
			Y.append([i, j])
	for (i, j) in Y:
		ad.append(j - i)
		if j == 0:
			md.append(0)
		elif i != 0 and j % i == 0:
			md.append(j // i)
		else:
			t += 1
	return min(len(set(ad)), t + len(set(md)))
a = ''
for _ in range(int(input())):
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	if x == y:
		a += '0\n'
		continue
	(X, ad, md, t, f) = ([], [], [], 0, False)
	for i in range(3):
		if x[i] != y[i]:
			X.append([x[i], y[i]])
	for (i, j) in X:
		ad.append(j - i)
		if j == 0:
			md.append(0)
		elif i != 0 and j % i == 0:
			md.append(j // i)
		else:
			t += 1
	res = min(len(set(ad)), t + len(set(md)))
	if res < 3:
		a += str(res) + '\n'
		continue
	(dd, Mmd, Mad) = ([], [], [])
	for i in range(3):
		for j in range(i + 1, 3):
			dd.append([x[i] - x[j], y[i] - y[j]])
	for k in range(3):
		i = dd[k][0]
		j = dd[k][1]
		if i != 0 and j % i == 0:
			Mmd.append(j // i)
			for l in range(3):
				aa = x[l]
				bb = y[l]
				if j // i != 0 and bb % (j // i) == 0:
					Mad.append(bb // (j // i) - aa)
	(tres, xx, tt, ii) = ([], [[x[0], x[1]], [x[1], x[2]], [x[0], x[2]]], [[y[0], y[1]], [y[1], y[2]], [y[0], y[2]]], [2, 0, 1])
	for i in ad + Mad:
		sx = [4]
		for k in range(len(xx)):
			if not (xx[k][0] + i != tt[k][0] and xx[k][1] + i != tt[k][1]):
				sx.append(ii[k])
		if len(sx) == 1:
			sx.extend([0, 1, 2])
		for k in sx:
			(ax, aX) = ([x[j] if k == j else i + x[j] for j in range(len(x))], [])
			for l in range(3):
				aX.append([ax[l], y[l]])
			tres.append(gOP(aX) + 1)
			if tres[-1] == 2:
				a += '2\n'
				f = True
				break
		if f:
			break
	if f:
		continue
	for i in md + Mmd:
		sx = [4]
		for k in range(len(xx)):
			try:
				if not (tt[k][0] / xx[k][0] == i and tt[k][1] / xx[k][1] == i):
					sx.append(ii[k])
			except:
				continue
		if len(sx) == 1:
			sx.extend([2, 1, 0])
		for k in sx:
			(mx, mX) = ([x[j] if k == j else i * x[j] for j in range(len(x))], [])
			for l in range(3):
				mX.append([mx[l], y[l]])
			tres.append(gOP(mX) + 1)
			if tres[-1] == 2:
				a += '2\n'
				f = True
				break
		if f:
			break
	if f:
		continue
	res = min(res, min(tres))
	a += str(res) + '\n'
print(a)


def a1(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if p + p1 == a and q == b and (r == c):
		return 1
	return -1

def a2(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if p == a and q + q1 == b and (r == c):
		return 1
	return -1

def a3(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if p == a and q == b and (r + r1 == c):
		return 1
	return -1

def a4(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if p1 == q1 and p + p1 == a and (q + q1 == b) and (r == c):
		return 1
	return -1

def a5(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if q1 == r1 and p == a and (q + q1 == b) and (r + r1 == c):
		return 1
	return -1

def a6(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if p1 == r1 and p + p1 == a and (q == b) and (r + r1 == c):
		return 1
	return -1

def a7(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if (q1 == r1 and p1 == q1) and p + p1 == a and (q + q1 == b) and (r + r1 == c):
		return 1
	return -1

def a8(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if p * p2 == a and q == b and (r == c):
		return 1
	return -1

def a9(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if p == a and q * q2 == b and (r == c):
		return 1
	return -1

def a10(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if p == a and q == b and (r * r2 == c):
		return 1
	return -1

def a11(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if p2 == q2 and p * p2 == a and (q * q2 == b) and (r == c):
		return 1
	return -1

def a12(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if q2 == r2 and p == a and (q * q2 == b) and (r * r2 == c):
		return 1
	return -1

def a13(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if p2 == r2 and p * p2 == a and (q == b) and (r * r2 == c):
		return 1
	return -1

def a14(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2):
	if (q2 == r2 and p2 == q2) and p * p2 == a and (q * q2 == b) and (r * r2 == c):
		return 1
	return -1

def b1(p, q, r, a, b, c):
	if q == b or r == c or p == a:
		return 2
	return -1

def b2(p, q, r, a, b, c):
	if b - q == c - r:
		return 2
	return -1

def b3(p, q, r, a, b, c):
	if q != 0 and r != 0 and (b % q == 0) and (c % r == 0) and (b // q == c // r):
		return 2
	return -1

def b4(p, q, r, a, b, c):
	if a - p == c - r:
		return 2
	return -1

def b5(p, q, r, a, b, c):
	if p != 0 and r != 0 and (a % p == 0) and (c % r == 0) and (a // p == c // r):
		return 2
	return -1

def b6(p, q, r, a, b, c):
	if b - q == a - p:
		return 2
	return -1

def b7(p, q, r, a, b, c):
	if p != 0 and q != 0 and (a % p == 0) and (b % q == 0) and (a // p == b // q):
		return 2
	return -1

def b8(p, q, r, a, b, c):
	if a - p + (c - r) == b - q:
		return 2
	return -1

def b9(p, q, r, a, b, c):
	if b - q + (c - r) == a - p:
		return 2
	return -1

def b10(p, q, r, a, b, c):
	if r != 0 and c % r == 0 and ((q + a - p) * c // r == b):
		return 2
	return -1

def b11(p, q, r, a, b, c):
	if r != 0 and c % r == 0 and ((p + b - q) * c // r == a):
		return 2
	return -1

def b12(p, q, r, a, b, c):
	if r != 0 and c % r == 0 and ((p + b - q) * c // r == a):
		return 2
	return -1

def b13(p, q, r, a, b, c):
	if r != 0 and c != 0 and (c % r == 0) and (a * r % c == 0) and (b * r % c == 0) and (a * r // c - p == b * r // c - q):
		return 2
	return -1

def b14(p, q, r, a, b, c):
	if b - q + (a - p) == c - r:
		return 2
	return -1

def b15(p, q, r, a, b, c):
	if p != 0 and a % p == 0 and ((q + c - r) * a // p == b):
		return 2
	return -1

def b16(p, q, r, a, b, c):
	if p != 0 and a % p == 0 and ((r + b - q) * a // p == c):
		return 2
	return -1

def b17(p, q, r, a, b, c):
	if p != 0 and a != 0 and (a % p == 0) and (b * p % a == 0) and (c * p % a == 0) and (b * p // a - q == c * p // a - r):
		return 2
	return -1

def b18(p, q, r, a, b, c):
	if q != 0 and b % q == 0 and ((p + c - r) * b // q == a):
		return 2
	return -1

def b19(p, q, r, a, b, c):
	if q != 0 and b % q == 0 and ((r + a - p) * b // q == c):
		return 2
	return -1

def b20(p, q, r, a, b, c):
	if q != 0 and b != 0 and (b % q == 0) and (a * q % b == 0) and (c * q % b == 0) and (a * q // b - p == c * q // b - r):
		return 2
	return -1

def b21(p, q, r, a, b, c):
	if p + c - r != 0 and q + c - r != 0 and (a % (p + c - r) == 0) and (b % (q + c - r) == 0) and (a // (p + c - r) == b // (q + c - r)):
		return 2
	return -1

def b22(p, q, r, a, b, c):
	if q + a - p != 0 and r + a - p != 0 and (b % (q + a - p) == 0) and (c % (r + a - p) == 0) and (b // (q + a - p) == c // (r + a - p)):
		return 2
	return -1

def b23(p, q, r, a, b, c):
	if p + b - q != 0 and r + b - q != 0 and (a % (p + b - q) == 0) and (c % (r + b - q) == 0) and (a // (p + b - q) == c // (r + b - q)):
		return 2
	return -1

def b24(p, q, r, a, b, c):
	if p != 0 and a % p == 0 and (q * a // p + (c - r) == b):
		return 2
	return -1

def b25(p, q, r, a, b, c):
	if q != 0 and b % q == 0 and (p * b // q + (c - r) == a):
		return 2
	return -1

def b26(p, q, r, a, b, c):
	if p != 0 and q != 0 and ((a - c + r) % p == 0) and ((b - c + r) % q == 0) and ((a - c + r) // p == (b - c + r) // q):
		return 2
	return -1

def b27(p, q, r, a, b, c):
	if p != 0 and r != 0 and (a % p == 0) and (c % r == 0) and (q * a * c // (p * r) == b):
		return 2
	return -1

def b28(p, q, r, a, b, c):
	if q != 0 and r != 0 and (b % q == 0) and (c % r == 0) and (p * b * c // (q * r) == a):
		return 2
	return -1

def b29(p, q, r, a, b, c):
	if p != 0 and q != 0 and (r != 0) and (c != 0) and (c % r == 0) and (a % p == 0) and (b % q == 0) and (a // p == b // q):
		return 2
	return -1

def b30(p, q, r, a, b, c):
	if r != 0 and c % r == 0 and (q * c // r + (a - p) == b):
		return 2
	return -1

def b31(p, q, r, a, b, c):
	if q != 0 and b % q == 0 and (r * b // q + (a - p) == c):
		return 2
	return -1

def b32(p, q, r, a, b, c):
	if q != 0 and r != 0 and ((b - a + p) % q == 0) and ((c - a + p) % r == 0) and ((b - a + p) // q == (c - a + p) // r):
		return 2
	return -1

def b33(p, q, r, a, b, c):
	if p != 0 and q != 0 and (a % p == 0) and (b % q == 0) and (r * b * a // (p * q) == c):
		return 2
	return -1

def b34(p, q, r, a, b, c):
	if p != 0 and q != 0 and (r != 0) and (a != 0) and (a % p == 0) and (b % q == 0) and (c % r == 0) and (b // q == c // r):
		return 2
	return -1

def b35(p, q, r, a, b, c):
	if r != 0 and c % r == 0 and (p * c // r + (b - q) == a):
		return 2
	return -1

def b36(p, q, r, a, b, c):
	if p != 0 and a % p == 0 and (r * a // p + (b - q) == c):
		return 2
	return -1

def b37(p, q, r, a, b, c):
	if p != 0 and r != 0 and ((a - b + q) % p == 0) and ((c - b + q) % r == 0) and ((a - b + q) // p == (c - b + q) // r):
		return 2
	return -1

def b38(p, q, r, a, b, c):
	if p != 0 and q != 0 and (r != 0) and (b != 0) and (b % q == 0) and (a % p == 0) and (c % r == 0) and (a // p == c // r):
		return 2
	return -1

def b39(p, q, r, a, b, c):
	if r != 0 and c % r == 0 and (a - p * c // r == b - q * c // r):
		return 2
	return -1

def b40(p, q, r, a, b, c):
	if p != 0 and a % p == 0 and (b - q * a // p == c - r * a // p):
		return 2
	return -1

def b41(p, q, r, a, b, c):
	if q != 0 and b % q == 0 and (a - p * b // q == c - r * b // q):
		return 2
	return -1

def b42(p, q, r, a, b, c):
	if p - q != 0 and q - r != 0 and ((a - b) % (p - q) == 0) and ((b - c) % (q - r) == 0) and ((a - b) // (p - q) == (b - c) // (q - r)):
		t = (a - b) // (p - q)
		if a - p * t == b - q * t and b - q * t == c - r * t:
			return 2
	return -1

def b43(p, q, r, a, b, c):
	if a - b != 0 and b - c != 0 and (p - q != 0) and (q - r != 0) and ((a - b) % (p - q) == 0) and ((b - c) % (q - r) == 0) and ((a - b) // (p - q) == (b - c) / (q - r)):
		t = (a - b) / (p - q)
		if a % t == 0 and b % t == 0 and (c % t == 0) and (a // t - p == b // t - q) and (b // t - q == c // t - r):
			return 2
	return -1
t = int(input())
for _ in range(t):
	(p, q, r) = map(int, input().split())
	(a, b, c) = map(int, input().split())
	ans = -1
	if p == a and q == b and (r == c):
		ans = 0
	else:
		if ans == -1:
			p1 = a - p
			q1 = b - q
			r1 = c - r
			p2 = 0
			q2 = 0
			r2 = 0
			if p != 0 and a % p == 0:
				p2 = a // p
			if q != 0 and b % q == 0:
				q2 = b // q
			if r != 0 and c % r == 0:
				r2 = c // r
			if ans == -1:
				ans = a1(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = a2(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = a3(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = a4(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = a5(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = a6(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = a7(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = a8(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = a9(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = a10(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = a11(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = a12(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = a13(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = a14(p, q, r, a, b, c, p1, q1, r1, p2, q2, r2)
			if ans == -1:
				ans = b1(p, q, r, a, b, c)
			if ans == -1:
				ans = b2(p, q, r, a, b, c)
			if ans == -1:
				ans = b3(p, q, r, a, b, c)
			if ans == -1:
				ans = b4(p, q, r, a, b, c)
			if ans == -1:
				ans = b5(p, q, r, a, b, c)
			if ans == -1:
				ans = b6(p, q, r, a, b, c)
			if ans == -1:
				ans = b7(p, q, r, a, b, c)
			if ans == -1:
				ans = b8(p, q, r, a, b, c)
			if ans == -1:
				ans = b9(p, q, r, a, b, c)
			if ans == -1:
				ans = b10(p, q, r, a, b, c)
			if ans == -1:
				ans = b11(p, q, r, a, b, c)
			if ans == -1:
				ans = b12(p, q, r, a, b, c)
			if ans == -1:
				ans = b13(p, q, r, a, b, c)
			if ans == -1:
				ans = b14(p, q, r, a, b, c)
			if ans == -1:
				ans = b15(p, q, r, a, b, c)
			if ans == -1:
				ans = b16(p, q, r, a, b, c)
			if ans == -1:
				ans = b17(p, q, r, a, b, c)
			if ans == -1:
				ans = b18(p, q, r, a, b, c)
			if ans == -1:
				ans = b19(p, q, r, a, b, c)
			if ans == -1:
				ans = b20(p, q, r, a, b, c)
			if ans == -1:
				ans = b21(p, q, r, a, b, c)
			if ans == -1:
				ans = b22(p, q, r, a, b, c)
			if ans == -1:
				ans = b23(p, q, r, a, b, c)
			if ans == -1:
				ans = b24(p, q, r, a, b, c)
			if ans == -1:
				ans = b25(p, q, r, a, b, c)
			if ans == -1:
				ans = b26(p, q, r, a, b, c)
			if ans == -1:
				ans = b27(p, q, r, a, b, c)
			if ans == -1:
				ans = b28(p, q, r, a, b, c)
			if ans == -1:
				ans = b29(p, q, r, a, b, c)
			if ans == -1:
				ans = b30(p, q, r, a, b, c)
			if ans == -1:
				ans = b31(p, q, r, a, b, c)
			if ans == -1:
				ans = b32(p, q, r, a, b, c)
			if ans == -1:
				ans = b33(p, q, r, a, b, c)
			if ans == -1:
				ans = b34(p, q, r, a, b, c)
			if ans == -1:
				ans = b35(p, q, r, a, b, c)
			if ans == -1:
				ans = b36(p, q, r, a, b, c)
			if ans == -1:
				ans = b37(p, q, r, a, b, c)
			if ans == -1:
				ans = b38(p, q, r, a, b, c)
			if ans == -1:
				ans = b39(p, q, r, a, b, c)
			if ans == -1:
				ans = b40(p, q, r, a, b, c)
			if ans == -1:
				ans = b41(p, q, r, a, b, c)
			if ans == -1:
				ans = b42(p, q, r, a, b, c)
			if ans == -1:
				ans = b43(p, q, r, a, b, c)
		if ans == -1:
			ans = 3
	print(ans)


def two_only(p, q, a, b):
	if p == a or q == b:
		return 1
	if a == b == 0:
		return 1
	if a - p == b - q:
		return 1
	if p == 0 or q == 0:
		return 2
	if a // p == b // q and a % p == 0 and (b % q == 0):
		return 1
	return 2
for _ in range(int(input())):
	(p, q, r) = list(map(int, input().split()))
	(a, b, c) = list(map(int, input().split()))
	if p == a and q == b and (r == c):
		print(0)
		continue
	if p == a:
		print(two_only(q, r, b, c))
		continue
	if b == q:
		print(two_only(p, r, a, c))
		continue
	if c == r:
		print(two_only(p, q, a, b))
		continue
	if a == b == c == 0:
		print(1)
		continue
	d1 = a - p
	d2 = b - q
	d3 = c - r
	x = False
	y = False
	z = False
	p1 = 0
	p2 = 0
	p3 = 0
	if d1 == d2 == d3:
		print(1)
		continue
	if p != 0 and a // p == a / p:
		x = True
		p1 = a // p
	if q != 0 and b // q == b / q:
		y = True
		p2 = b // q
	if r != 0 and c // r == c / r:
		z = True
		p3 = c // r
	if x and y and z:
		if p1 == p2 == p3:
			print(1)
			continue
	d = [d1, d2, d3]
	d.sort()
	if d[1] == d[0] or d[1] == d[2]:
		print(2)
		continue
	if d[2] == d[1] + d[0] or d[1] == d[2] + d[0] or d[0] == d[1] + d[2]:
		print(2)
		continue
	if x and y and z:
		pr = [p1, p2, p3]
		pr.sort()
		if pr[1] == pr[0] or pr[1] == pr[2]:
			print(2)
			continue
		if pr[2] == pr[1] * pr[0] or pr[1] == pr[2] * pr[0] or pr[0] == pr[1] * pr[2]:
			print(2)
			continue
	if x and y:
		if p1 == p2:
			print(2)
			continue
	if y and z:
		if p2 == p3:
			print(2)
			continue
	if x and z:
		if p1 == p3:
			print(2)
			continue
	s = [p, q, r]
	t = [a, b, c]
	two = False
	for _ in range(3):
		(p, q, r) = s
		(a, b, c) = t
		l = False
		m = False
		n = False
		l1 = 0
		l2 = 0
		l3 = 0
		x = False
		y = False
		z = False
		p1 = 0
		p2 = 0
		p3 = 0
		d1 = a - p
		d2 = b - q
		d3 = c - r
		if p != 0 and a // p == a / p:
			x = True
			p1 = a // p
		if q != 0 and b // q == b / q:
			y = True
			p2 = b // q
		if r != 0 and c // r == c / r:
			z = True
			p3 = c // r
		if p != q:
			if (a - b) % (p - q) == 0:
				l1 = (a - b) // (p - q)
				l = True
		if r != q:
			if (c - b) % (r - q) == 0:
				l3 = (c - b) // (r - q)
				n = True
		if p != r:
			if (a - c) % (p - r) == 0:
				l2 = (a - c) // (p - r)
				m = True
		if l and m and n:
			if l1 == l2 == l3:
				two = True
				break
		if l:
			if (a - b) * r == (p - q) * c:
				two = True
				break
			diff = c - r
			if a * (q + diff) == b * (p + diff):
				two = True
				break
			if p * (b - diff) == q * (a - diff):
				two = True
				break
		if z:
			if (p + d2) * p3 == a:
				two = True
				break
			if p * p3 + d2 == a:
				two = True
				break
		if y:
			if (p + d3) * p2 == a:
				two = True
				break
			if p * p2 + d3 == a:
				two = True
				break
		s.append(s[0])
		del s[0]
		t.append(t[0])
		del t[0]
	if two:
		print(2)
	else:
		print(3)