def Dot(p,q):
res=0
for i in range(3):
res+=p[i]*q[i]
return res
def solve():
x1,y1,z1=map(int,input().split())
a,b=map(int,input().split())
x2,y2,z2=map(int,input().split())
d,e=map(int,input().split())
det=a*e-b*d
if det==0:
if Dot((x2-x1,y2-y1,z2-z1),(a,b,0))==0:
print(2)
else:
print(4)
return
if x1==x2 and y1==y2:
print(2)
return
x1,y1,z1,x2,y2,z2=x1*det*2,y1*det*2,z1*det*2,x2*det*2,y2*det*2,z2*det*2
c=a*x1+b*y1
f=d*x2+e*y2
Cx=(e*c-b*f)//det
Cy=(-d*c+a*f)//det
M1=((x1+x2)//2,(y1+y2)//2,(z1+z2)//2)
R=0
R=(x1-M1[0])**2+(y1-M1[1])**2+(z1-M1[2])**2
Mx=M1[0]
My=M1[1]
d=(Cx-Mx)*(Cx-Mx)+(Cy-My)*(Cy-My)
if d<=R:
if z1==z2 and d==R:
if (x1,y1)==(Cx,Cy) or (x2,y2)==(Cx,Cy):
print(4)
return
print(3)
else:
print(4)
for _ in range(int(input())):
solve()