Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.

Chef is a software developer, so he has to switch between different languages sometimes. Each programming language has some features, which are represented by integers here.

Currently, Chef has to use a language with two given features A and B. He has two options --- switching to a language with two features A_{1} and B_{1}, or to a language with two features A_{2} and B_{2}. All four features of these two languages are pairwise distinct.

Tell Chef whether he can use the first language, the second language or neither of these languages (if no single language has all the required features).

------ Input Format ------ 

- 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 and only line of each test case contains six space-separated integers A, B, A_{1}, B_{1}, A_{2}, B_{2}.

------ Output Format ------ 

For each test case, print a single line containing the integer 1 if Chef should switch to the first language, or 2 if Chef should switch to the second language, or 0 if Chef cannot switch to either language.

------ Constraints ------ 

$1 ≤ T ≤ 288$
$1 ≤ A, B, A_{1}, B_{1}, A_{2}, B_{2} ≤ 4$
$A, B$ are distinct
$A_{1}, B_{1}, A_{2}, B_{2}$ are pairwise distinct

------ subtasks ------ 

Subtask #1 (100 points): original constraints

----- Sample Input 1 ------ 
3
1 2 2 1 3 4
3 4 2 1 4 3
1 2 1 3 2 4
----- Sample Output 1 ------ 
1
2
0
----- explanation 1 ------ 
Example case 1: The first language has the required features --- features $1$ and $2$.

Example case 2: The second language has the required features --- features $3$ and $4$.

Example case 3: Neither language has both features $1$ and $2$.

Difficulty: EASY

Solutions:
t = int(input())
for _ in range(t):
	(a, b, a1, b1, a2, b2) = map(int, input().split())
	if a1 == a and b1 == b or (b1 == a and a1 == b):
		print('1')
	elif a2 == a and b2 == b or (b2 == a and a2 == b):
		print('2')
	else:
		print('0')


test = int(input())
ans = []
while test:
	test = test - 1
	(A, B, A1, B1, A2, B2) = [int(x) for x in input().split()]
	if (A == A1 or A == B1) and (B == A1 or B == B1):
		ans.append(1)
	elif (A == A2 or A == B2) and (B == A2 or B == B2):
		ans.append(2)
	else:
		ans.append(0)
for i in ans:
	print(i)


for i in range(int(input())):
	X = map(int, input().split(' '))
	(A, B, A1, B1, A2, B2) = list(X)
	if (A == A1 or A == B1) and (B == A1 or B == B1):
		print(1)
	elif (A == A2 or A == B2) and (B == A2 or B == B2):
		print(2)
	else:
		print(0)


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


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


for i in range(int(input())):
	l = list(map(int, input().split()))
	sublist1 = l[0:2]
	sublist2 = l[2:4]
	sublist3 = l[4:6]
	if all((c in sublist2 for c in sublist1)):
		print('1')
	elif all((c in sublist3 for c in sublist1)):
		print('2')
	else:
		print('0')


for i in range(int(input())):
	(a, b, a1, b1, a2, b2) = map(int, input().split())
	if a == a1 and b == b1:
		print('1')
	elif a == b1 and b == a1:
		print('1')
	elif a == a2 and b == b2:
		print('2')
	elif a == b2 and b == a2:
		print('2')
	else:
		print('0')


T = int(input())
for t in range(T):
	(A, B, A1, B1, A2, B2) = map(int, input().split())
	if (A1 == A or A1 == B) and (B1 == B or B1 == A):
		print(1)
	elif (A2 == A or A2 == B) and (B2 == B or B2 == A):
		print(2)
	else:
		print(0)


t = int(input())
while t > 0:
	(a, b, a1, b1, a2, b2) = map(int, input().split())
	req = [a, b]
	p1 = [a1, b1]
	p2 = [a2, b2]
	if req == p1 or req == p1[-1::-1]:
		print(1)
	elif req == p2 or req == p2[-1::-1]:
		print(2)
	else:
		print(0)
	t -= 1


t = int(input())
for i in range(t):
	(a, b, a1, b1, a2, b2) = map(int, input().split())
	s = set((a, b))
	s1 = set((a1, b1))
	s2 = set((a2, b2))
	if s == s1:
		print(1)
	elif s == s2:
		print(2)
	else:
		print(0)


for _ in range(int(input())):
	l = [int(x) for x in input().split()]
	if (l[0], l[1]) == (l[2], l[3]) or (l[0], l[1]) == (l[3], l[2]):
		print(1)
	elif (l[0], l[1]) == (l[4], l[5]) or (l[0], l[1]) == (l[5], l[4]):
		print(2)
	else:
		print(0)


n = int(input())
for i in range(n):
	(A, B, A1, B1, A2, B2) = map(int, input().split(' '))
	if {A, B} == {A1, B1}:
		print(1)
	elif {A, B} == {A2, B2}:
		print(2)
	else:
		print(0)


t = int(input())
for i in range(t):
	(a, b, a1, b1, a2, b2) = map(int, input().split())
	out = 0
	if a in [a1, b1] and b in [a1, b1]:
		out = 1
	if a in [a2, b2] and b in [a2, b2]:
		out = 2
	print(out)


T = int(input())
for t in range(T):
	(A, B, A1, B1, A2, B2) = map(int, input().split())
	one = [A1, B1]
	two = [A2, B2]
	if A in one:
		if B in one:
			print('1')
		else:
			print('0')
	elif A in two:
		if B in two:
			print('2')
		else:
			print('0')
	else:
		print('0')


T = int(input())
for i in range(T):
	(A, B, A1, B1, *other) = map(int, input().split(' '))
	answ = [A, B]
	lst1 = [A1, B1]
	lst2 = other
	if answ == lst1 or answ == list(reversed(lst1)):
		print(1)
	elif answ == lst2 or answ == list(reversed(lst2)):
		print(2)
	else:
		print(0)


for i in range(int(input())):
	(a, b, c, d, e, f) = map(int, input().split())
	x = set((a, b))
	y = set((c, d))
	z = set((e, f))
	if x == y:
		print(1)
	elif x == z:
		print(2)
	else:
		print(0)


T = int(input())
for i in range(T):
	(A, B, a1, b1, a2, b2) = map(int, input().split())
	if a1 == A and b1 == B or (a1 == B and b1 == A):
		print(1)
	elif a2 == A and b2 == B or (a2 == B and b2 == A):
		print(2)
	else:
		print(0)


for i in range(int(input())):
	(A, B, A1, B1, A2, B2) = map(int, input().split(' '))
	lang1 = set((A1, B1))
	lang2 = set((A2, B2))
	if A in lang1 and B in lang1:
		print('1')
	elif A in lang2 and B in lang2:
		print('2')
	else:
		print('0')


for i in range(int(input())):
	(req_fet1, req_fet2, lang1_fet1, lang1_fet2, lang2_fet1, lang2_fet2) = map(int, input().split(' '))
	count = 0
	if req_fet1 in (lang1_fet1, lang1_fet2):
		if req_fet2 in (lang1_fet1, lang1_fet2):
			print('1')
		else:
			count += 1
	else:
		count += 1
	if req_fet1 in (lang2_fet1, lang2_fet2):
		if req_fet2 in (lang2_fet1, lang2_fet2):
			print('2')
		else:
			count += 1
	else:
		count += 1
	if count > 1:
		print('0')


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


t = int(input())
for i in range(t):
	(a, b, c, d, e, f) = list(map(int, input().split()))
	l1 = [a, b]
	l2 = [c, d]
	l3 = [e, f]
	l1.sort()
	l2.sort()
	l3.sort()
	if l1 == l2:
		print('1')
	elif l1 == l3:
		print('2')
	else:
		print('0')


T = int(input())
for i in range(T):
	z = list(map(int, input().split()))
	l = []
	l.append(z[0])
	l.append(z[1])
	l1 = []
	l1.append(z[2])
	l1.append(z[3])
	l2 = []
	l2.append(z[4])
	l2.append(z[5])
	l.sort()
	l1.sort()
	l2.sort()
	if l == l1:
		print(1)
	elif l == l2:
		print(2)
	elif l != l1 and l != l2:
		print(0)


for i in range(int(input())):
	a = list(map(int, input().split(' ')))
	(j, k) = (a[0], a[1])
	if a[2] == j and a[3] == k or (a[2] == k and a[3] == j):
		print(1)
	elif a[4] == j and a[5] == k or (a[4] == k and a[5] == j):
		print(2)
	else:
		print(0)


t = int(input())
for i in range(t):
	(a, s, d, g, h, j) = map(int, input().split())
	if (s == d or s == g) and (a == d or a == g):
		print('1')
	elif (s == h or s == j) and (a == h or a == j):
		print('2')
	else:
		print('0')


for i in range(int(input())):
	l = list(map(int, input().split()))
	(a, b, c) = ([l[0], l[1]], [l[2], l[3]], [l[4], l[5]])
	(d, e, f) = (sorted(a), sorted(b), sorted(c))
	if e == d:
		print('1')
	elif f == d:
		print('2')
	else:
		print('0')


def solve(a, b, a_1, b_1, a_2, b_2):
	if (a == a_1 or a == b_1) and (b == a_1 or b == b_1):
		return '1'
	elif (a == a_2 or a == b_2) and (b == a_2 or b == b_2):
		return '2'
	else:
		return '0'
t = int(input())
for i in range(t):
	(a, b, a_1, b_1, a_2, b_2) = map(int, input().split())
	print(solve(a, b, a_1, b_1, a_2, b_2))
	i += 1


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


for i in range(int(input())):
	(a, b, x, y, m, n) = map(int, input().split())
	set_1 = set((a, b))
	set_2 = set((x, y))
	set_3 = set((m, n))
	if set_1 == set_2:
		print(1)
	elif set_1 == set_3:
		print(2)
	else:
		print(0)


t = int(input())
while t > 0:
	(a, b, a1, b1, a2, b2) = map(int, input().split())
	l = []
	l.append(a)
	l.append(b)
	if a1 in l and b1 in l:
		print(1)
	elif a2 in l and b2 in l:
		print(2)
	else:
		print(0)
	t -= 1


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


t = int(input())
vowels = ['a', 'e', 'i', 'o', 'u']
for i in range(t):
	arr = list(map(int, input().split()))
	(a, b) = (arr[0], arr[1])
	f1 = arr[2:4]
	f2 = arr[4:6]
	if a in f1 and b in f1:
		print(1)
	elif a in f2 and b in f2:
		print(2)
	else:
		print(0)


for _ in range(int(input())):
	L = input()[::-1]
	(a, b) = (L.index(L[-1]), L.index(L[-3]))
	if a < 3 and b < 3:
		print(2)
	elif 3 < a < 7 and 3 < b < 7:
		print(1)
	else:
		print(0)


t = int(input())
for i in range(t):
	str = input()
	str = str.split()
	a = int(str[0])
	b = int(str[1])
	c = int(str[2])
	d = int(str[3])
	e = int(str[4])
	f = int(str[5])
	if a == c and b == d or (a == d and b == c):
		print('1')
	elif a == e and b == f or (a == f and b == e):
		print('2')
	else:
		print('0')


for i in range(int(input())):
	(x, y, x1, y1, x2, y2) = map(int, input().split())
	if (x == x1 or x == y1) and (y == y1 or y == x1):
		print(1)
	elif (x == x2 or x == y2) and (y == y2 or y == x2):
		print(2)
	else:
		print(0)