def solve():
a, b, a1, b1, a2, b2 = int(input('Enter 6 numbers: '))
if(a>b):
temp = a
a = b
b = temp
if(a1> b1):
temp = a1
a1=b1
b1=temp
if(a2>b2):
temp=a2
a2=b2
b2=temp
if (a==a1 && b==b1):
print(1)
elif(a == a2 && b==b2):
print(2)
else:
print(0)
solve()
t=int(input())
l=[]
s=set()
while(t>0):
for i in range(0,4):
i=int(input())
s.add(i)
l.append(i)
#print(len(s))
if(len(s)==4):
print("2")
elif(len(s)==1):
print("0")
elif(len(s)==3):
print("1")
elif(len(s)==2):
b=0
c=l[0]
for i in range(0,3):
if(c==l[i+1]):
b=b+1
#print(b)
if(b==1):
print("2")
else:
print("1")
s.clear()
l.clear()
t=t-1