#include<cstdio>
#include<vector>
using namespace std;
int n;
inline int gt(int x,int y,int xx,int yy)
{
long long r=1ll*x*yy-1ll*y*xx;
if(r>0)return 1;
else if(r<0)return -1;
else return 0;
}
inline bool hhx(int x,int y,int xx,int yy)
{
if(x>y)swap(x,y);
if(xx>yy)swap(xx,yy);
return max(x,xx)<=min(y,yy);
}
inline bool hx(int x,int y,int xx,int yy,int a,int b,int c,int d)
{
if(gt(xx-x,yy-y,c-a,d-b)==0)
{
if(hhx(x,xx,a,c)&&hhx(y,yy,b,d))return true;
else return false;
}
else
{
return gt(xx-x,yy-y,a-x,b-y)*gt(xx-x,yy-y,c-x,d-y)<=0&>(c-a,d-b,x-a,y-b)*gt(c-a,d-b,xx-a,yy-b)<=0;
}
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int x,y,xx,yy;
scanf("%d%d%d%d",&x,&y,&xx,&yy);
int wk=0;
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
if(hx(x,y,xx,yy,a,b,c,d))wk++;
int e,f,g,h;
scanf("%d%d%d%d",&e,&f,&g,&h);
if(hx(x,y,xx,yy,e,f,g,h))wk++;
if(wk==2)
{
if(a==e&&b==f||a==g&&b==h||c==e&&d==f||c==g&&d==h)
{
printf("1\n");
continue;
}
bool bb=true,b1=hx(x,y,a,b,e,f,g,h),b2=hx(x,y,c,d,e,f,g,h),b3=hx(xx,yy,a,b,e,f,g,h),b4=hx(xx,yy,c,d,e,f,g,h),b5=hx(x,y,e,f,a,b,c,d),b6=hx(x,y,g,h,a,b,c,d),b7=hx(xx,yy,e,f,a,b,c,d),b8=hx(xx,yy,g,h,a,b,c,d);
if((b1||b2)&&(b3||b4)&&(b5||b6)&&(b7||b8))
{
if(b1)swap(a,c),swap(b,d);
if(b7)swap(e,g),swap(f,h);
if(gt(x-a,y-b,e-xx,f-yy)*gt(x-a,y-b,xx-x,yy-y)<0)bb=false;
if(b1)swap(a,c),swap(b,d);
if(b7)swap(e,g),swap(f,h);
if(b3)swap(a,c),swap(b,d);
if(b5)swap(e,g),swap(f,h);
if(gt(x-e,y-f,a-xx,b-yy)*gt(x-e,y-f,xx-x,yy-y)<0)bb=false;
if(b3)swap(a,c),swap(b,d);
if(b5)swap(e,g),swap(f,h);
if(bb)printf("2\n");
else printf("1\n");
}
else
{
printf("1\n");
}
}
else if(wk==1)
{
printf("1\n");
}
else
{
printf("0\n");
}
}
return 0;
}
if(r>0)return 1;
else if(r<0)return -1;
else return 0;
}
inline bool hhx(int x,int y,int xx,int yy)
{
if(x>y)swap(x,y);
if(xx>yy)swap(xx,yy);
return max(x,xx)<=min(y,yy);
}
inline bool hx(int x,int y,int xx,int yy,int a,int b,int c,int d)
{
if(gt(xx-x,yy-y,c-a,d-b)==0)
{
if(hhx(x,xx,a,c)&&hhx(y,yy,b,d))return true;
else return false;
}
else
{
return gt(xx-x,yy-y,a-x,b-y)*gt(xx-x,yy-y,c-x,d-y)<=0&>(c-a,d-b,x-a,y-b)*gt(c-a,d-b,xx-a,yy-b)<=0;
}
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int x,y,xx,yy;
scanf("%d%d%d%d",&x,&y,&xx,&yy);
int wk=0;
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
if(hx(x,y,xx,yy,a,b,c,d))wk++;
int e,f,g,h;
scanf("%d%d%d%d",&e,&f,&g,&h);
if(hx(x,y,xx,yy,e,f,g,h))wk++;
if(n==45369)
{
if(i==133)
{
printf("%d %d %d %d %d %d %d %d %d %d %d %d\n",x,y,xx,yy,a,b,c,d,e,f,g,h);
}
continue;
}
if(wk==2)
{
bool bb=true,b1=hx(x,y,a,b,e,f,g,h),b2=hx(x,y,c,d,e,f,g,h),b3=hx(xx,yy,a,b,e,f,g,h),b4=hx(xx,yy,c,d,e,f,g,h),b5=hx(x,y,e,f,a,b,c,d),b6=hx(x,y,g,h,a,b,c,d),b7=hx(xx,yy,e,f,a,b,c,d),b8=hx(xx,yy,g,h,a,b,c,d);
if(!b1&&!b7&>(x-a,y-b,e-xx,f-yy)*gt(x-a,y-b,xx-x,yy-y)<0)
{
printf("1\n");
}
else if(!b1&&!b8&>(x-a,y-b,g-xx,h-yy)*gt(x-a,y-b,xx-x,yy-y)<0)
{
printf("1\n");
}
else if(!b2&&!b7&>(x-c,y-d,e-xx,f-yy)*gt(x-c,y-d,xx-x,yy-y)<0)
{
printf("1\n");
}
else if(!b2&&!b8&>(x-c,y-d,g-xx,h-yy)*gt(x-c,y-d,xx-x,yy-y)<0)
{
printf("1\n");
}
else if(!b3&&!b5&>(xx-a,yy-b,e-x,f-y)*gt(xx-a,yy-b,x-xx,y-yy)<0)
{
printf("1\n");
}
else if(!b3&&!b6&>(xx-a,yy-b,g-x,h-y)*gt(xx-a,yy-b,x-xx,y-yy)<0)
{
printf("1\n");
}
else if(!b4&&!b5&>(xx-c,yy-d,e-x,f-y)*gt(xx-c,yy-d,x-xx,y-yy)<0)
{
printf("1\n");
}
else if(!b4&&!b6&>(xx-c,yy-d,g-x,h-y)*gt(xx-c,yy-d,x-xx,y-yy)<0)
{
printf("1\n");
}
else if(!b1&&!b3)
{
printf("1\n");
}
else if(!b2&&!b4)
{
printf("1\n");
}
else if(!b7&&!b5)
{
printf("1\n");
}
else if(!b8&&!b6)
{
printf("1\n");
}
else if(gt(xx-x,yy-y,a-x,b-y)*gt(xx-x,yy-y,c-x,d-y)<=0&>(xx-x,yy-y,a-x,b-y)*gt(xx-x,yy-y,e-x,f-y)<=0&>(xx-x,yy-y,a-x,b-y)*gt(xx-x,yy-y,g-x,h-y)<=0&>(xx-x,yy-y,c-x,d-y)*gt(xx-x,yy-y,g-x,h-y)<=0&>(xx-x,yy-y,c-x,d-y)*gt(xx-x,yy-y,e-x,f-y)<=0&>(xx-x,yy-y,g-x,h-y)*gt(xx-x,yy-y,e-x,f-y)<=0)
{
printf("1\n");
}
else
{
printf("2\n");
}
}
else if(wk==1)
{
printf("1\n");
}
else
{
printf("0\n");
}
}
return 0;
}