Burenka came to kindergarden. This kindergarten is quite strange, so each kid there receives two fractions ($\frac{a}{b}$ and $\frac{c}{d}$) with integer numerators and denominators. Then children are commanded to play with their fractions.

Burenka is a clever kid, so she noticed that when she claps once, she can multiply numerator or denominator of one of her two fractions by any integer of her choice (but she can't multiply denominators by $0$). Now she wants know the minimal number of claps to make her fractions equal (by value). Please help her and find the required number of claps!


-----Input-----

The first line contains one integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. Then follow the descriptions of each test case.

The only line of each test case contains four integers $a$, $b$, $c$ and $d$ ($0 \leq a, c \leq 10^9$, $1 \leq b, d \leq 10^9$) — numerators and denominators of the fractions given to Burenka initially.


-----Output-----

For each test case print a single integer — the minimal number of claps Burenka needs to make her fractions equal.


-----Examples-----

Input
8
2 1 1 1
6 3 2 1
1 2 2 3
0 1 0 100
0 1 228 179
100 3 25 6
999999999 300000000 666666666 100000000
33 15 0 84
Output
1
0
2
0
1
1
1
1


-----Note-----

In the first case, Burenka can multiply $c$ by $2$, then the fractions will be equal.

In the second case, fractions are already equal.

In the third case, Burenka can multiply $a$ by $4$, then $b$ by $3$. Then the fractions will be equal ($\frac{1 \cdot 4}{2 \cdot 3} = \frac{2}{3}$).

Difficulty: EASY

Solutions:
import sys

def solve():
	(a, b, c, d) = map(int, sys.stdin.readline().split())
	x = a * d
	y = b * c
	if x == y:
		print(0)
	elif x == 0 or y == 0:
		print(1)
	elif x % y == 0 or y % x == 0:
		print(1)
	else:
		print(2)

def main():
	for i in range(int(sys.stdin.readline())):
		solve()
main()


for s in [*open(0)][1:]:
	(a, b, c, d) = map(int, s.split())
	a *= d
	b *= c
	print((a != b) + (a * b and a % b > 0 < b % a))


import sys
input = sys.stdin.readline

def print(*args, end='\n', sep=' ') -> None:
	sys.stdout.write(sep.join(map(str, args)) + end)

def Solve():
	for t in range(int(input())):
		(a, b, c, d) = map(int, input().split())
		if a * d == c * b:
			print(0)
		elif not a or not b or (not c) or (not d):
			print(1)
		elif a * d % (b * c) == 0 or b * c % (a * d) == 0:
			print(1)
		else:
			print(2)
Solve()


import sys
input = sys.stdin.readline

def solve():
	(a, b, c, d) = map(int, input().split())
	if a * d == b * c:
		return 0
	elif a == 0 or c == 0:
		return 1
	elif a * d % (b * c) == 0 or b * c % (a * d) == 0:
		return 1
	else:
		return 2
for _ in range(int(input())):
	print(solve())


for sum in [*open(0)][1:]:
	(w, x, y, z) = map(int, sum.split())
	w *= z
	x *= y
	print((w != x) + (w * x and w % x > 0 < x % w))


import sys
input = sys.stdin.readline

def solve(a, b, c, d):
	if a * d == b * c:
		return 0
	if a == 0 or c == 0:
		return 1
	if a * d % (b * c) == 0 or b * c % (a * d) == 0:
		return 1
	if b * c == 1 or a * d == 1:
		return 1
	return 2
t = int(input())
for _ in range(t):
	(a, b, c, d) = [int(x) for x in input().split()]
	print(solve(a, b, c, d))


from re import I
import sys
printf = sys.stdout.write

def intput():
	return int(sys.stdin.readline())

def get_int():
	return map(int, sys.stdin.readline().strip().split())

def get_lis():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_liss():
	return sys.stdin.readline().split()

def get_ints():
	return sys.stdin.readline().split()

def get_str():
	return sys.stdin.readline().strip()

def pop_zeros(items):
	while items[-1] == 0:
		items.pop()

def compute_lcm(x, y):
	if x > y:
		greater = x
	else:
		greater = y
	while True:
		if greater % x == 0 and greater % y == 0:
			lcm = greater
			break
		greater += 1
	return lcm
from collections import defaultdict
import math
t = intput()
while t:
	(a, b, c, d) = get_int()
	if a * d == b * c:
		printf('0')
		printf('\n')
	else:
		p = a * d
		pp = b * c
		if pp != 0 and p % pp == 0 or (p != 0 and pp % p == 0):
			printf('1')
			printf('\n')
		else:
			printf('2')
			printf('\n')
	t -= 1


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	(a, b, c, d) = inlt()
	if a * d == c * b:
		print(0)
	elif min(a * d, c * b) == 0:
		print(1)
	elif c * b % (d * a) == 0 or d * a % (c * b) == 0:
		print(1)
	else:
		print(2)


from sys import stdin
input = stdin.readline

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
from math import sqrt

def perfect_sq(n):
	x = int(sqrt(n))
	while x * x < n:
		x += 1
	while x * x > n:
		x -= 1
	return x * x == n
for _ in range(ii()):
	(a, b, c, d) = li()
	if a * d == b * c:
		print(0)
		continue
	if a == 0 or c == 0:
		print(1)
		continue
	if a * d % (b * c) == 0 or b * c % (a * d) == 0:
		print(1)
	else:
		print(2)


import sys
s = sys.stdin.read()
lines = s.split('\n')
for line in lines[1:-1]:
	(a, b, c, d) = map(int, line.split())
	(max_A, min_B) = (max(a * d, b * c), min(a * d, b * c))
	if a * d == c * b:
		print('0')
	elif a == 0 and c == 0:
		print('0')
	elif a == 0 or c == 0:
		print('1')
	elif max_A % min_B == 0:
		print('1')
	else:
		print('2')


import math
ans = []

def lcm(a, b):
	return a * b // math.gcd(a, b)
for tc in range(int(input())):
	(a, b, c, d) = list(map(int, input().split()))
	if a * d == b * c:
		ans.append(0)
	elif a == 0 and c == 0:
		ans.append(0)
	elif a == 0 or c == 0:
		ans.append(1)
	else:
		(temp1, temp2) = (a * d, b * c)
		l_c_m = lcm(temp1, temp2)
		if l_c_m == temp1 or l_c_m == temp2:
			ans.append(1)
		else:
			ans.append(2)
for i in ans:
	print(i)


n = int(input())
lst = []
for i in range(n):
	lst.append(str(input()))

def count(lst):
	lst3 = []
	for q in lst:
		count = 0
		lst2 = q.split(' ')
		a = int(lst2[0])
		b = int(lst2[1])
		c = int(lst2[2])
		d = int(lst2[3])
		x = a * d
		y = b * c
		if x == y:
			count = 0
		elif x == 0 or y == 0:
			count = 1
		elif x % y == 0 or y % x == 0:
			count = 1
		else:
			count = 2
		lst3.append(count)
	return lst3
for d in count(lst):
	print(d)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def solve():
	(a, b, c, d) = inlt()
	(n1, n2) = (a * d, b * c)
	if a == 0 and c == 0:
		return 0
	if a == 0 or c == 0:
		return 1
	if n1 == n2:
		return 0
	elif n1 % n2 == 0 or n2 % n1 == 0:
		return 1
	else:
		return 2
for _ in range(inp()):
	print(solve())


import sys
input = sys.stdin.readline
n = int(input())
ans = 0
for _ in range(n):
	(a, b, c, d) = map(int, input().split())
	if a == 0 and c != 0 or (a != 0 and c == 0):
		ans = 1
	elif a * d == c * b:
		ans = 0
	elif a * d % (c * b) == 0 or c * b % (a * d) == 0:
		ans = 1
	else:
		ans = 2
	print(ans)


import sys
import collections
import bisect
import math
from functools import lru_cache
for _ in range(int(input())):
	(a, b, c, d) = list(map(int, sys.stdin.readline().split()))
	x1 = a * d
	x2 = b * c
	if x1 == x2:
		print(0)
	elif x1 == 0 or x2 == 0 or x1 % x2 == 0 or (x2 % x1 == 0):
		print(1)
	else:
		print(2)


def f(a, b, c, d):
	if a * d == b * c:
		return 0
	if a * c == 0 and a != c:
		return 1
	if a * c == 0 and a != ca:
		return 1
	if a != 0 and c != 0:
		if a * d % (b * c) == 0 or b * c % (a * d) == 0:
			return 1
		else:
			return 2
list = []
x = int(input())
for item in range(x):
	y = input().split(' ')
	list += [f(int(y[0]), int(y[1]), int(y[2]), int(y[3]))]
for z in list:
	print(z)


arr = []
n = int(input())
for i in range(n):
	(a, b, c, d) = list(map(int, input().split(sep=' ')))
	if a * d == b * c:
		arr += '0'
	elif c == 0 or a == 0:
		arr += '1'
	elif a * d > b * c:
		num = a * d // (b * c)
		if a * d == b * c * num:
			arr += '1'
		else:
			arr += '2'
	elif a * d < b * c:
		num = b * c // (a * d)
		if a * d * num == b * c:
			arr += '1'
		else:
			arr += '2'
for i in range(n):
	print(arr[i])


num = int(input())
results = []
for i in range(num):
	(a, b, c, d) = map(int, input().split())
	num1 = a * d
	num2 = b * c
	if [num1, num2].count(0) == 1:
		results.append(1)
	elif num1 == num2:
		results.append(0)
	elif num1 % num2 == 0 or num2 % num1 == 0:
		results.append(1)
	else:
		results.append(2)
for result in results:
	print(result)


import sys
input = sys.stdin.readline

def solve():
	(a, b, c, d) = map(int, input().split(' '))
	if a == 0 and c == 0:
		print(0)
	elif a == 0 or c == 0:
		print(1)
	elif c * b % (a * d) == 0 and a * d % (b * c) == 0:
		print(0)
	elif c * b % (a * d) == 0 or a * d % (b * c) == 0:
		print(1)
	elif c * b % (a * d) != 0 or a * d % (b * c) != 0:
		print(2)
	else:
		print(0)
t = int(input())
while t > 0:
	solve()
	t -= 1


import bisect
from collections import deque, defaultdict
T = int(input())
q = []
for i in range(T):
	x = input().split()
	(a, b, c, d) = (int(x[0]), int(x[1]), int(x[2]), int(x[3]))
	q.append((a, b, c, d))

def solve(a, b, c, d):
	if a * d == b * c:
		print(0)
		return
	if 0 in [a, c]:
		print(1)
		return
	if a * d % (b * c) == 0:
		print(1)
		return
	if b * c % (a * d) == 0:
		print(1)
		return
	print(2)
for (a, b, c, d) in q:
	solve(a, b, c, d)


t = int(input())
res = []
for _ in range(t):
	(a, b, c, d) = [int(x) for x in input().split()]
	x = a * d
	y = b * c
	if x < y:
		(x, y) = (y, x)
	if a == 0 and c == 0:
		res.append(0)
	elif a == 0 or c == 0:
		res.append(1)
	elif x % y == 0 and x // y == 1:
		res.append(0)
	elif x % y == 0:
		res.append(1)
	else:
		res.append(2)
for val in res:
	print(val)


t = int(input())
res = []
for _ in range(t):
	(a, b, c, d) = list(map(int, input().split()))
	v = [a * d, b * c]
	y = max(v)
	x = min(v)
	if y == x:
		res.append(0)
	elif x == 0 or y % x == 0:
		res.append(1)
	else:
		res.append(2)
for r in res:
	print(r)


def ans(a, b, c, d):
	if a * d == c * b:
		return 0
	else:
		x = a * d
		y = c * b
		if x == 0 or y == 0:
			return 1
		if max(x, y) % min(x, y) == 0:
			return 1
		else:
			return 2
T = int(input())
l = []
for _ in range(T):
	(a, b, c, d) = map(int, input().split())
	r = ans(a, b, c, d)
	l.append(r)
for i in range(T):
	print(l[i])


t = int(input())
respuesta = []
for k in range(t):
	n = input()
	n = list(map(int, n.split(' ')))
	x = n[0] * n[3]
	y = n[1] * n[2]
	if x == y:
		respuesta.append(0)
	elif y != 0 and x % y == 0 or (x != 0 and y % x == 0):
		respuesta.append(1)
	else:
		respuesta.append(2)
for i in respuesta:
	print(i)


number = input()
array = []
binaryArray = []
for i in range(int(number)):
	array = [int(j) for j in input().split()]
	binaryArray.append(array)
for i in binaryArray:
	a = i[0]
	b = i[1]
	c = i[2]
	d = i[3]
	a *= d
	b *= c
	if a == b:
		print(0)
	elif a == 0 or b == 0 or a % b == 0 or (b % a == 0):
		print(1)
	else:
		print(2)


def solve_one():
	(a, b, c, d) = map(int, input().split())
	if a * d == b * c:
		return 0
	if a * c == 0 or a * d % (b * c) == 0 or b * c % (a * d) == 0:
		return 1
	return 2

def solve():
	t = int(input())
	anss = []
	for _ in range(t):
		anss.append(solve_one())
	for ans in anss:
		print(ans)
solve()


t = int(input())
m = []
for i in range(t):
	s = list(map(int, input().split()))
	m.append(s)

def a(l):
	if l[0] == 0:
		if l[2] == 0:
			return 0
		else:
			return 1
	elif l[2] == 0:
		return 1
	elif l[0] * l[3] % (l[1] * l[2]) == 0 or l[1] * l[2] % (l[0] * l[3]) == 0:
		if l[0] * l[3] / (l[1] * l[2]) == 1 / 1 or l[1] * l[2] / (l[0] * l[3]) == 1 / 1:
			return 0
		else:
			return 1
	else:
		return 2
for i in range(t):
	print(a(m[i]))


t = int(input())
ans = [0] * t
f = 0
while t > 0:
	(a, b, c, d) = map(int, input().split())
	x = a * d
	y = c * b
	if x == y:
		ans[f] = 0
	elif c == 0 or a == 0 or x % y == 0 or (y % x == 0):
		ans[f] = 1
	else:
		ans[f] = 2
	t -= 1
	f += 1
for i in ans:
	print(i)


t = int(input())
result = []
for i in range(t):
	(a, b, c, d) = list(map(int, input().split(' ')))
	if (a == 0) | (c == 0):
		if (a == 0) & (c != 0):
			result.append(1)
		elif (c == 0) & (a != 0):
			result.append(1)
		else:
			result.append(0)
	elif a * d == b * c:
		result.append(0)
	elif (a * d % (c * b) == 0) | (c * b % (a * d) == 0):
		result.append(1)
	else:
		result.append(2)
for i in result:
	print(i)


n = int(input())
count = 0
outlist = []
while count < n:
	count += 1
	(a, b, c, d) = [int(i) for i in input().split(' ')]
	if a * d == b * c:
		outlist.append('0')
	elif a / b == 0 or c / d == 0:
		outlist.append('1')
	elif max(a * d, b * c) % min(a * d, b * c) == 0:
		outlist.append('1')
	else:
		outlist.append('2')
for res in outlist:
	print(res)


import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	ad = a * d
	bc = b * c
	if ad == bc:
		print(0)
	else:
		num_gcd = math.gcd(ad, bc)
		if num_gcd == ad or num_gcd == bc:
			print(1)
		else:
			print(2)


t = int(input())
for _ in range(t):
	arr = input().split()
	arr = [int(i) for i in arr]
	(res1, res2) = (arr[0] * arr[3], arr[1] * arr[2])
	if res1 == res2:
		print(0)
	elif res1 == 0 or res2 == 0:
		print(1)
	elif res1 % res2 == 0 or res2 % res1 == 0:
		print(1)
	else:
		print(2)


for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	if a * d == b * c:
		print(0)
	elif a == 0 or c == 0:
		print(1)
	elif b * c % (a * d) == 0 or a * d % (b * c) == 0:
		print(1)
	else:
		print(2)


def solve():
	x = int(input())
	for _ in range(x):
		[a, b, c, d] = list(map(int, input().split()))
		if a * d == c * b:
			print(0)
		elif a == 0 or c == 0:
			print(1)
		elif a * d > c * b and a * d % (c * b) == 0:
			print(1)
		elif c * b > a * d and c * b % (a * d) == 0:
			print(1)
		else:
			print(2)
solve()


t = int(input())
for i in range(t):
	input1 = input()
	(a, b, c, d) = input1.split()
	a = int(a)
	b = int(b)
	c = int(c)
	d = int(d)
	m = a * d
	n = c * b
	if m == n:
		print(0)
	elif m == 0 or n == 0:
		print(1)
	elif m % n == 0 or n % m == 0:
		print(1)
	else:
		print(2)


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	p = a * d
	q = b * c
	if p == q:
		print(0)
	elif q != 0 and p % q == 0 or (p != 0 and q % p == 0):
		print(1)
	else:
		print(2)


testcases = int(input())
for i in range(testcases):
	(a, b, c, d) = map(int, input().split())
	mul1 = a * d
	mul2 = b * c
	if mul1 == mul2:
		print('0')
	elif mul2 != 0 and mul1 % mul2 == 0 or (mul1 != 0 and mul2 % mul1 == 0):
		print('1')
	else:
		print('2')


t = int(input())
while t:
	(a, b, c, d) = map(int, input().split())
	x = a * d
	y = c * b
	if x == y:
		res = 0
	elif x > y:
		if y != 0 and x % y == 0:
			res = 1
		elif y == 0:
			res = 1
		else:
			res = 2
	elif x != 0 and y % x == 0:
		res = 1
	elif x == 0:
		res = 1
	else:
		res = 2
	print(res)
	t -= 1


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split(' '))
	e = a * d
	f = b * c
	if e == f:
		print(0)
	elif e == 0 or f == 0:
		print(1)
	elif e % f == 0 or f % e == 0:
		print(1)
	else:
		print(2)


t = int(input())
t0 = 0
t1 = 1
t2 = 2
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	if a * d == b * c:
		print(t0)
	elif b * c != 0 and a * d % (b * c) == 0:
		print(t1)
	elif a * d != 0 and b * c % (a * d) == 0:
		print(t1)
	else:
		print(t2)


import math
t = int(input())
for h in range(t):
	(a, b, c, d) = [int(i) for i in input().split()]
	if a * d == c * b:
		print('0')
	elif a == 0 and (not c == 0) or (not a == 0 and c == 0):
		print('1')
	else:
		val_1 = a * d
		val_2 = b * c
		if val_1 % val_2 == 0 or val_2 % val_1 == 0:
			print('1')
		else:
			print('2')


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	p1 = a * d
	p2 = c * b
	if p1 == p2:
		print(0)
	elif p2 != 0 and p1 % p2 == 0:
		print(1)
	elif p1 != 0 and p2 % p1 == 0:
		print(1)
	else:
		print(2)


N = int(input())
for i in range(N):
	(a, b, c, d) = map(int, input().split())
	re1 = a * d
	re2 = b * c
	if a * d == b * c:
		print(0)
	elif re1 == 0 or re2 == 0:
		print(1)
	elif re1 > re2:
		if re1 % re2 == 0:
			print(1)
		else:
			print(2)
	elif re2 % re1 == 0:
		print(1)
	else:
		print(2)


def sol():
	(a, b, c, d) = map(int, input().split())
	ans = 0
	A = a * d
	B = b * c
	if A == B:
		return 0
	elif A == 0 or B == 0:
		return 1
	if A % B == 0 or B % A == 0:
		return 1
	else:
		return 2
for i in range(int(input())):
	print(sol(), end='\n')


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	if a * d == b * c:
		print('0')
	else:
		x = a * d
		y = b * c
		if y != 0 and x % y == 0:
			print('1')
		elif x != 0 and y % x == 0:
			print('1')
		else:
			print('2')


def clap():
	(a, b, c, d) = map(int, input().split())
	if a * d == b * c:
		print(0)
		return
	elif a == 0 or c == 0:
		print(1)
	else:
		x = a * d
		y = b * c
		mx = max(x, y)
		mn = min(x, y)
		if mx % mn == 0:
			print(1)
		else:
			print(2)
t = int(input())
while t:
	clap()
	t -= 1


for _ in range(int(input())):
	[a, b, c, d] = list(map(int, input().split()))
	if a * d == b * c:
		print(0)
	else:
		n2 = b * c
		n1 = a * d
		if n2 != 0 and n1 % n2 == 0:
			print(1)
		elif n1 != 0 and n2 % n1 == 0:
			print(1)
		else:
			print(2)


t = int(input())
for testcases in range(t):
	[a, b, c, d] = list(map(int, input().split()))
	if a == 0:
		if c == 0:
			print(0)
		else:
			print(1)
	elif c == 0:
		print(1)
	elif a * d == c * b:
		print(0)
	elif a * d % (c * b) == 0 or b * c % (a * d) == 0:
		print(1)
	else:
		print(2)


t = int(input())
for z in range(t):
	(a, b, c, d) = [int(x) for x in input().split()]
	if a * d == 0:
		if b * c == 0:
			print(0)
		else:
			print(1)
	elif b * c == 0:
		print(1)
	elif a * d == b * c:
		print(0)
	elif a * d % (b * c) == 0 or b * c % (a * d) == 0:
		print(1)
	else:
		print(2)


for i in range(int(input())):
	a = list(map(int, input().split()))
	if a[0] * a[3] == a[1] * a[2]:
		print(0)
	elif a[0] == 0 or a[2] == 0 or a[1] * a[2] % (a[0] * a[3]) == 0 or (a[0] * a[3] % (a[1] * a[2]) == 0):
		print(1)
	else:
		print(2)


t = int(input())
for tt in range(t):
	(a, b, c, d) = map(int, input().split())
	x = a * d
	y = b * c
	if x == y:
		print(0)
	elif x == 0 or y == 0 or x % y == 0 or (y % x == 0):
		print(1)
	else:
		print(2)


class Problem1720A:

	def main():
		cases = int(input())
		i = 0
		while i < cases:
			line = input()
			(a, b, c, d) = map(int, line.split(' '))
			if a == 0 and c == 0 or a * d == b * c:
				print(0)
			elif a == 0 or c == 0 or a * d % (b * c) == 0 or (b * c % (a * d) == 0):
				print(1)
			else:
				print(2)
			i += 1
Problem1720A.main()


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	temp1 = a * d
	temp2 = c * b
	if temp1 == temp2:
		print(0)
	elif temp1 == 0 or temp2 == 0:
		print(1)
	elif temp1 % temp2 == 0 or temp2 % temp1 == 0:
		print(1)
	else:
		print(2)


for _ in range(int(input())):
	(a, b, c, d) = [int(x) for x in input().split()]
	(n1, n2) = (d * a, b * c)
	if n1 == n2:
		print(0)
	elif n1 != 0 and n2 != 0:
		if n1 % n2 == 0 or n2 % n1 == 0:
			print(1)
		else:
			print(2)
	elif n1 == 0 or n2 == 0:
		print(1)
	else:
		print(2)


def ii():
	return int(input())

def il(sep=' '):
	if sep == '':
		return [int(i) for i in input()]
	return [int(i) for i in input().split(sep)]
manant = ii()
for manantt in range(manant):
	(a, b, c, d) = il()
	(x, y) = (a * d, b * c)
	if x == y:
		print(0)
		continue
	if x == 0 or y == 0 or (x % y == 0 or y % x == 0):
		print(1)
		continue
	print(2)


t = int(input())
while t != 0:
	(a, b, c, d) = map(int, input().split())
	(s, u) = (a * d, b * c)
	if s == u:
		print('0\n')
	elif u != 0 and s % u == 0 or (s != 0 and u % s == 0):
		print('1\n')
	else:
		print('2\n')
	t -= 1


tests_number = int(input())
for i in range(tests_number):
	array = list(map(int, input().split()))
	left_cross = array[0] * array[3]
	right_cross = array[1] * array[2]
	if left_cross == right_cross:
		print(0)
	elif left_cross == 0 or right_cross == 0:
		print(1)
	elif left_cross % right_cross == 0 or right_cross % left_cross == 0:
		print(1)
	else:
		print(2)


for x in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	adb = a * d
	cdd = c * b
	if adb == cdd:
		print(0)
	elif cdd != 0 and adb % cdd == 0 or (adb != 0 and cdd % adb == 0):
		print(1)
	else:
		print(2)