There is a field of size $2 \times 2$. Each cell of this field can either contain grass or be empty. The value $a_{i, j}$ is $1$ if the cell $(i, j)$ contains grass, or $0$ otherwise.

In one move, you can choose one row and one column and cut all the grass in this row and this column. In other words, you choose the row $x$ and the column $y$, then you cut the grass in all cells $a_{x, i}$ and all cells $a_{i, y}$ for all $i$ from $1$ to $2$. After you cut the grass from a cell, it becomes empty (i. e. its value is replaced by $0$).

Your task is to find the minimum number of moves required to cut the grass in all non-empty cells of the field (i. e. make all $a_{i, j}$ zeros).

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 16$) — the number of test cases. Then $t$ test cases follow.

The test case consists of two lines, each of these lines contains two integers. The $j$-th integer in the $i$-th row is $a_{i, j}$. If $a_{i, j} = 0$ then the cell $(i, j)$ is empty, and if $a_{i, j} = 1$ the cell $(i, j)$ contains grass.


-----Output-----

For each test case, print one integer — the minimum number of moves required to cut the grass in all non-empty cells of the field (i. e. make all $a_{i, j}$ zeros) in the corresponding test case.


-----Examples-----

Input
3
0 0
0 0
1 0
0 1
1 1
1 1
Output
0
1
2


-----Note-----

None

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
for _ in range(int(input())):
	a = sum(list(map(int, input().split()))) + sum(list(map(int, input().split())))
	if a == 0:
		print(0)
	elif a == 4:
		print(2)
	else:
		print(1)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	arr = [a, b, c, d]
	z = arr.count(0)
	if z == 4:
		print(0)
	elif z == 0:
		print(2)
	else:
		print(1)


t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = b.count(1) + a.count(1)
	if c == 4:
		print(2)
	elif c == 0:
		print(0)
	else:
		print(1)


for t in range(int(input())):
	s = list(map(int, input().split()))
	s1 = list(map(int, input().split()))
	if s[0] == 1 and s1[1] == 1 and (s[1] == 1) and (s1[0] == 1):
		print(2)
	elif s[0] == 1 or s1[0] == 1 or s[1] == 1 or (s1[1] == 1):
		print(1)
	else:
		print(0)


T = int(input())
while T:
	T -= 1
	row1 = list(map(int, input().split()))
	row2 = list(map(int, input().split()))
	if row1 == [0, 0] and row2 == [0, 0]:
		print(0)
	elif row1 == [1, 1] and row2 == [1, 1]:
		print(2)
	else:
		print(1)


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


n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	a += list(map(int, input().split()))
	c_ = a.count(1)
	if c_ == 0:
		print(0)
	elif c_ == 4:
		print(2)
	else:
		print(1)


T = int(input())
for _ in range(T):
	(tl, tr) = map(int, input().split())
	(bl, br) = map(int, input().split())
	if tl == 1 and br == 1 and (tr == 1) and (bl == 1):
		print(2)
		continue
	if tl == 0 and tr == 0 and (bl == 0) and (br == 0):
		print(0)
		continue
	print(1)


testcases = int(input())
for i in range(testcases):
	(a, b) = [int(x) for x in input().split(' ')]
	(c, d) = [int(x) for x in input().split(' ')]
	if a == 1 and b == 1 and (c == 1) and (d == 1):
		print(2)
	elif a == 0 and b == 0 and (c == 0) and (d == 0):
		print(0)
	else:
		print(1)


for p in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	l = [a, b, c, d]
	c = l.count(1)
	if c == 0:
		print('0')
	elif c == 1 or c == 2 or c == 3:
		print('1')
	else:
		print('2')


for x in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	count = 0
	if a + b + c + d == 4:
		print(2)
	elif a + b + c + d == 0:
		print(0)
	else:
		print(1)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	(x, y) = map(int, input().split())
	if m + n + x + y == 0:
		print(0)
	elif m + n + x + y == 4:
		print(2)
	else:
		print(1)


numTestCases = int(input())
for i in range(numTestCases):
	count = 0
	for j in range(2):
		matrixRow = list(map(int, input().split(' ')))
		for el in matrixRow:
			if el == 1:
				count += 1
	if count == 4:
		print(2)
	elif count >= 1:
		print(1)
	else:
		print(0)


def exe():
	x = a + b + c + d
	if x == 0:
		return 0
	elif x == 4:
		return 2
	else:
		return 1
for i in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	lst = [[a, b], [c, d]]
	print(exe())


t = int(input())
for i in range(t):
	lst1 = []
	inp1 = input().split()
	for j in inp1:
		lst1.append(int(j))
	lst2 = []
	inp2 = input().split()
	for j in inp2:
		lst2.append(int(j))
	if lst1[0] == 0 and lst1[1] == 0 and (lst2[0] == 0) and (lst2[1] == 0):
		print(0)
	elif lst1[0] == 1 and lst1[1] == 1 and (lst2[0] == 1) and (lst2[1] == 1):
		print(2)
	else:
		print(1)


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


res = []
p = False
for s in [*open(0)][1:]:
	res += s.split()
	if not p:
		p = True
	else:
		p = False
		if res.count('1') == 0:
			print(0)
		elif res.count('1') == 2 or res.count('1') == 3 or res.count('1') == 1:
			print(1)
		else:
			print(2)
		res = []


for x in range(int(input())):
	a = input()
	b = input()
	s = 0
	s += a.count('1')
	s += b.count('1')
	if s == 0:
		print(0)
	elif s == 4:
		print(2)
	else:
		print(1)


t = int(input())
for i in range(t):
	g = 0
	n = input()
	x = input()
	m = x.split()
	n = n.split()
	if int(m[0]) == 1:
		g = g + 1
	if int(m[1]) == 1:
		g = g + 1
	if int(n[0]) == 1:
		g = g + 1
	if int(n[1]) == 1:
		g = g + 1
	if g == 0:
		print(0)
	elif g == 1 or g == 2 or g == 3:
		print(1)
	elif g == 4:
		print(2)


n = int(input())
for i in range(n):
	j = 0
	r = []
	r.append(input().split())
	r.append(input().split())
	for k in range(2):
		for l in range(2):
			if r[k][l] == '1':
				j += 1
	if j == 0:
		print(0)
	elif j == 1 or j == 2 or j == 3:
		print(1)
	else:
		print(2)


n = int(input())
for i in range(n):
	l = []
	count = 0
	for j in range(2):
		l.append(list(map(int, input().split())))
	for ele in l:
		count += ele.count(1)
	if count == 4:
		print(2)
	elif count == 0:
		print(0)
	else:
		print(1)


for i in range(int(input())):
	r1 = input().split()
	r2 = input().split()
	if r1 == ['0', '0'] and r2 == ['0', '0']:
		print(0)
	elif r1 == ['1', '1'] and r2 == ['1', '1']:
		print(2)
	else:
		print(1)


n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	(x, y) = list(map(int, input().split()))
	if a == b == x == y:
		if a == 0:
			print(0)
		else:
			print(2)
	if [a, b, x, y].count(1) == 1:
		print(1)
	if [a, b, x, y].count(1) == 3 or [a, b, x, y].count(1) == 2:
		print(1)


t = int(input())
for i in range(t):
	x = sum(list(map(int, input().split())))
	y = sum(list(map(int, input().split())))
	if x + y == 0:
		print(0)
	elif x + y < 4:
		print(1)
	else:
		print(2)


nums = int(input())
needs = []
for k in range(nums):
	x = 0
	row1 = [int(c) for c in input().split(' ')]
	row2 = [int(c) for c in input().split(' ')]
	col1 = [row1[0], row2[0]]
	col2 = [row1[1], row2[1]]
	Z = sum(row1) + sum(row2)
	if Z == 0:
		x = 0
	elif Z in [1, 2, 3]:
		x = 1
	else:
		x = 2
	needs.append(x)
for each in needs:
	print(each)


t = int(input())
for j in range(t):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	s = a + b + c + d
	if s == 0:
		print(0)
	elif s == 1 or s == 2 or s == 3:
		print(1)
	else:
		print(2)


for _ in range(int(input())):
	(arr, cnt) = ([], 0)
	for i in range(2):
		arr.append(list(map(int, input().split())))
		cnt += arr[i].count(1)
	if cnt == 4:
		print(2)
	elif cnt == 0:
		print(0)
	else:
		print(1)


T = int(input())
q = []
for i in range(T):
	x = input().split()
	(a, b) = (int(x[0]), int(x[1]))
	x = input().split()
	(c, d) = (int(x[0]), int(x[1]))
	q.append([a, b, c, d])

def solve(data):
	ans = sum(data)
	if ans == 0:
		print(0)
	elif ans == 4:
		print(2)
	else:
		print(1)
for data in q:
	solve(data)


n = int(input())
for i in range(n):
	mat = []
	count = 0
	mat.append([int(x) for x in input().split(' ')])
	mat.append([int(x) for x in input().split(' ')])
	for i in range(len(mat)):
		for j in range(len(mat)):
			if mat[i][j] == 1:
				count += 1
	if count == 0:
		print(0)
	elif count == 4:
		print(2)
	else:
		print(1)


t = int(input())
campos = []
for a in range(t):
	linha1 = list(map(int, input().split()))
	linha2 = list(map(int, input().split()))
	campos.append([linha1, linha2])
for b in campos:
	if sum(b[0]) == 0 and sum(b[1]) == 0:
		print(0)
	elif sum(b[0]) == 2 and sum(b[1]) == 2:
		print(2)
	else:
		print(1)


for i in range(int(input())):
	a = []
	x = []
	s = 0
	for j in range(2):
		x = list(map(int, input().split()))
		s += sum(x)
		a.append(x)
	if s == 4:
		print(2)
	elif s == 0:
		print(0)
	else:
		print(1)


w = int(input())
for i in range(w):
	t = list(map(int, input().split()))
	l = list(map(int, input().split()))
	o = [1, 1]
	p = [0, 0]
	if t == o and l == o:
		print(2)
	elif t == p and l == p:
		print(0)
	else:
		print(1)


n = int(input())
ans = []
for i in range(n):
	(a, b) = input().split()
	(c, d) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	d = int(d)
	flag = 0
	if a == 0 and b == 0 and (c == 0) and (d == 0):
		ans.append(0)
		flag = 1
	if (a == 1 and d == 1) and (b == 1 and c == 1):
		ans.append(2)
		flag = 1
	if flag == 0:
		ans.append(1)
for i in range(n):
	print(ans[i])


for _ in range(int(input())):
	lst1 = list(map(int, input().split()))
	lst2 = list(map(int, input().split()))
	if lst1[0] == 0 and lst1[1] == 0 and (lst2[0] == 0) and (lst2[1] == 0):
		print(0)
	elif lst1[0] == 1 and lst1[1] == 1 and (lst2[0] == 1) and (lst2[1] == 1):
		print(2)
	else:
		print(1)


for i in range(int(input())):
	s = input().split()
	d = input().split()
	if int(s[1]) + int(s[0]) + int(d[1]) + int(d[0]) == 0:
		print(0)
	elif int(s[1]) + int(s[0]) + int(d[1]) + int(d[0]) == 1:
		print(1)
	elif int(s[1]) + int(s[0]) + int(d[1]) + int(d[0]) == 2:
		print(1)
	elif int(s[1]) + int(s[0]) + int(d[1]) + int(d[0]) == 3:
		print(1)
	elif int(s[1]) + int(s[0]) + int(d[1]) + int(d[0]) == 4:
		print(2)


t = int(input())
for i in range(t):
	n = map(int, input().split())
	m = map(int, input().split())
	lis = list(n)
	mis = list(m)
	if lis.count(0) == 2 and mis.count(0) == 2:
		print(0)
	elif lis.count(1) == 2 and mis.count(1) == 2:
		print(2)
	else:
		print(1)


def gf_main():
	first_line = input()
	second_line = input()
	first_line = [int(x) for x in first_line.split()]
	second_line = [int(x) for x in second_line.split()]
	all_sum = sum(first_line) + sum(second_line)
	if all_sum == 0:
		return 0
	if all_sum == 4:
		return 2
	return 1
n = int(input())
for i in range(n):
	print(gf_main())


t = int(input())
for _ in range(t):
	(a11, a12) = map(int, input().split())
	(a21, a22) = map(int, input().split())
	b = a11 + a12 + a21 + a22
	if b == 4:
		print(2)
	elif b == 0:
		print(0)
	else:
		print(1)


t = int(input(''))
for i in range(t):
	nums = []
	a = input('').rsplit()
	b = input('').rsplit()
	nums.extend(a)
	nums.extend(b)
	if set(nums) == {'0'}:
		print(0)
	elif (set(nums[0:2]) == {'0'} or set(nums[2:]) == {'0'}) or nums == ['1', '0', '0', '1'] or nums == ['0', '1', '1', '0'] or (nums == ['1', '0', '1', '0']) or (nums == ['0', '1', '0', '1']) or (nums.count('0') == 1):
		print(1)
	else:
		print(2)


for _ in range(int(input())):
	x12 = list(map(int, input().split()))
	x34 = list(map(int, input().split()))
	k = sum(x12) + sum(x34)
	if k == 0:
		print(0)
	elif k == 4:
		print(2)
	else:
		print(1)


t = int(input())
for _ in range(t):
	a = [list(map(int, input().split())) for _ in range(2)]
	if a[0] == [0, 0] and a[1] == [0, 0]:
		print(0)
	elif a[0] == [1, 1] and a[1] == [1, 1]:
		print(2)
	else:
		print(1)


N = int(input())
graph = []
counter = 0
for i in range(N):
	graph = []
	counter = 0
	graph.append(input().split())
	graph.append(input().split())
	for j in range(2):
		for k in range(2):
			if graph[j][k] == '1':
				counter += 1
	if counter == 1 or counter == 2 or counter == 3:
		print(1)
	elif counter == 0:
		print(0)
	elif counter == 4:
		print(2)


k = int(input())
for i in range(k):
	d1 = input().split()
	d2 = input().split()
	summa = int(d1[0]) + int(d1[1]) + int(d2[0]) + int(d2[1])
	if summa == 0:
		print(0)
	elif summa == 4:
		print(2)
	else:
		print(1)


t = int(input())
for _ in range(t):
	s = sum((int(i) for i in input().split())) + sum((int(i) for i in input().split()))
	if s == 4:
		print(2)
	elif s > 0:
		print(1)
	else:
		print(0)


for _ in range(int(input())):
	(n, s) = (4, 0)
	for _ in range(2):
		s += list(map(int, input().split()))[:2].count(1)
	print(0 if s == 0 else 2 if s == 4 else 1)


from collections import Counter

def solve():
	a1 = getInt()
	a2 = getInt()
	c1 = a1.count(1)
	c2 = a2.count(1)
	if c1 + c2 == 0:
		print(0)
	elif c1 + c2 == 4:
		print(2)
	else:
		print(1)

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def getInt():
	return list(map(int, input().split()))
for _ in range(int(input())):
	solve()


for _ in [0] * int(input()):
	l = input() + input()
	a = l.count('1')
	if a == 4:
		print(2)
	elif a > 0:
		print(1)
	else:
		print(0)


for _ in range(int(input())):
	c = input().count('1')
	c += input().count('1')
	if not c:
		print(0)
	elif c == 4:
		print(2)
	else:
		print(1)


t = int(input())
for i in range(t):
	(t1, t2) = input().split()
	a = int(t1)
	b = int(t2)
	(t3, t4) = input().split()
	c = int(t3)
	d = int(t4)
	if a + b + c + d == 4:
		ans = 2
	elif a + b + c + d > 0:
		ans = 1
	else:
		ans = 0
	print(ans)


import array as arr
t = int(input())
arr3 = []
for i in range(t):
	p = 1
	(k, l) = map(int, input().split())
	(y, u) = map(int, input().split())
	arr1 = arr.array('i', [k, l])
	arr2 = arr.array('i', [y, u])
	if not arr1[0] and (not arr1[1]) and (not arr2[0]) and (not arr2[1]):
		p = p - 1
	if arr1[0] and (not arr1[1]) and (not arr2[0]) and arr2[1] or (not arr1[0] and arr1[1] and arr2[0] and (not arr2[1])):
		p = 1
	if arr1[0] and arr1[1] and arr2[0] and arr2[1]:
		p = p + 1
	if arr1[0] == arr2[0] == 1 and arr1[1] == arr2[1] == 0 or (arr1[0] == arr2[0] == 0 and arr1[1] == arr2[1] == 1):
		p = 1
	if arr1[0] and arr1[1] and (not arr2[0]) and (not arr2[1]) or (not arr1[0] and (not arr1[1]) and arr2[0] and arr2[1]):
		p = 1
	arr3.append(p)
for i in range(t):
	print(arr3[i])


p = int(input())
for i in range(p):
	m = input()
	r = input()
	if m == '1 1' and r == '1 1':
		print(2)
	elif r == '0 0' and m == '0 0':
		print(0)
	else:
		print(1)


I = input
exec(int(I()) * "k=(I()+I()).count('1');print(k>>1or k);")


num = int(input())
for i in range(num):
	countOne = 0
	for j in range(2):
		a = input()
		countOne += a.count('1')
	if countOne == 0:
		print(0)
	elif countOne == 4:
		print(2)
	else:
		print(1)


for _ in range(int(input())):
	s = [input(), input()]
	if s[0] == '0 0' and s[1] == '0 0':
		print(0)
	elif s[0] == '1 1' and s[1] == '1 1':
		print(2)
	else:
		print(1)


t = int(input())
for i in range(t):
	(p, q) = map(int, input().split())
	(r, s) = map(int, input().split())
	if p == q == r == s == 0:
		print('0')
	elif p and q and r and (s == 1):
		print('2')
	else:
		print('1')


t = int(input())
for _ in range(t):
	(s1, s2) = (int(ii) for ii in input().split())
	(s3, s4) = (int(ii) for ii in input().split())
	s = s1 + s2 + s3 + s4
	if s == 0:
		print(0)
	elif s == 4:
		print(2)
	else:
		print(1)


for _ in range(int(input())):
	s = input() + input()
	f1 = s.count('1')
	if f1 == 0:
		print(0)
	elif f1 == 4:
		print(2)
	else:
		print(1)


MOD = 10 ** 9 + 7
fac_mem = [1]

def fac(n):
	while len(fac_mem) < n + 1:
		fac_mem.append(fac_mem[-1] * len(fac_mem) % MOD)
	return fac_mem[n]

def perm(n, k):
	return fac(n) * pow(fac(k), MOD - 2, MOD) % MOD

def comb(n, k):
	return fac(n) * pow(fac(k) * fac(n - k) % MOD, MOD - 2, MOD) % MOD

class Tree:

	def __init__(self, id):
		self.id = id
		self.parent = None
		self.children = []

	def __repr__(self):
		if self.children:
			return f'{self.id} -> [' + ', '.join((str(c) for c in self.children)) + ']'
		else:
			return str(self.id)
for case in range(int(input())):
	s = 0
	s += sum([int(j) for j in input().split()])
	s += sum([int(j) for j in input().split()])
	if s == 0:
		print(0)
	elif s == 4:
		print(2)
	else:
		print(1)


t = int(input())
for _ in range(t):
	x1 = sum(map(int, input().split()))
	x2 = sum(map(int, input().split()))
	if x1 == x2 == 0:
		print(0)
	elif x1 == x2 == 2:
		print(2)
	else:
		print(1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	n = (a, b, c, d).count(1)
	print(0 if n == 0 else 1 if n < 4 else 2)


t = int(input())
while t:
	t -= 1
	s = 0
	(x, y) = map(int, input().split())
	(w, e) = map(int, input().split())
	s = x + y + w + e
	if s == 0:
		print(0)
	elif s == 4:
		print(2)
	else:
		print(1)


T = int(input())
for testcase in range(1, T + 1):
	(a, b) = list(map(int, input().split()))
	(c, d) = list(map(int, input().split()))
	s = sum([a, b, c, d])
	if s == 0:
		print(0)
	elif s == 4:
		print(2)
	else:
		print(1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = sum(a)
	d = sum(b)
	if c + d == 4:
		print(2)
		continue
	if c + d == 0:
		print(0)
		continue
	print(1)


for _ in range(int(input())):
	(n1, m1) = map(int, input().split())
	(n2, m2) = map(int, input().split())
	if n1 + n2 + m1 + m2 == 0:
		print(0)
	elif n1 == n2 == m1 == m2 == 1:
		print(2)
	else:
		print(1)


t = int(input())
for _ in range(t):
	grid = []
	for _ in range(2):
		grid.append([int(x) for x in input().split()])
	if grid[0][0] == 1 and grid[0][1] == 1 and (grid[1][0] == 1) and (grid[1][1] == 1):
		print(2)
	elif grid[0][0] == 0 and grid[0][1] == 0 and (grid[1][0] == 0) and (grid[1][1] == 0):
		print(0)
	else:
		print(1)


def solve():
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	if arr.count(1) + brr.count(1) == 4:
		print(2)
		return
	if arr.count(1) + brr.count(1) == 0:
		print(0)
		return
	print(1)
	return
for i in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	field = input().strip() + input().strip()
	if field == '0 00 0':
		print(0)
	elif field == '1 11 1':
		print(2)
	else:
		print(1)


def solve():
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = sum(a) + sum(b)
	if s == 4:
		print(2)
	elif s:
		print(1)
	else:
		print(0)
for _ in range(int(input())):
	solve()


n = int(input())
for i in range(n):
	x = input() + ' ' + input()
	if x == '0 0 0 0':
		print(0)
	elif x == '1 1 1 1':
		print(2)
	else:
		print(1)


t = int(input())
for i in range(t):
	(a11, a12) = map(int, input().split())
	(a21, a22) = map(int, input().split())
	if a11 and a12 and a21 and a22:
		print(2)
	elif not a11 and (not a12) and (not a21) and (not a22):
		print(0)
	else:
		print(1)


def solve():
	a = map(int, input().split())
	b = map(int, input().split())
	c = sum(a) + sum(b)
	if c == 0:
		print(0)
	elif c == 1 or c == 2 or c == 3:
		print(1)
	else:
		print(2)
	return

def main():
	for _ in range(int(input())):
		solve()
	return
main()


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = a + list(map(int, input().split()))
	if 0 not in b:
		print(2)
	elif 1 not in b:
		print(0)
	else:
		print(1)


t = int(input())
while t:
	t = t - 1
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	lis = [a, b, c, d]
	if lis.count(0) == 4:
		print(0)
	elif lis.count(0) == 0:
		print(2)
	else:
		print(1)


t = int(input())
for i in range(t):
	(a1, a2) = map(int, input().split())
	(a3, a4) = map(int, input().split())
	if a1 == a2 == a3 == a4 == 0:
		print(0)
	elif a1 == a2 == a3 == a4 == 1:
		print(2)
	else:
		print(1)


import sys
input = sys.stdin.readline

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


for testcase in range(int(input())):
	l1 = input().split()
	l2 = input().split()
	if not '1' in l1 and (not '1' in l2):
		print('0')
	elif not '0' in l1 and (not '0' in l2):
		print('2')
	else:
		print('1')


def val(a, b, c, d):
	sum = a + b + c + d
	if sum == 0:
		return 0
	if sum == 4:
		return 2
	return 1
T = int(input())
for _ in range(T):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	print(val(a, b, c, d))


t = int(input())
for _ in range(t):
	l1 = input().split()
	l2 = input().split()
	num = 0
	for elem in l1:
		if elem == '1':
			num += 1
	for elem in l2:
		if elem == '1':
			num += 1
	if num == 0:
		print(0)
	elif num == 4:
		print(2)
	else:
		print(1)