/*
TASK: mov
LANG: C++
*/
#include <iostream>
#define m 2000000
using namespace std;

struct point{long double x,y;};
point a,b,c,d,v,p,q;
long double k,t;
int mas[3],out,n,i,j;

int ccw(point p1,point p2,point p3)
{long double l,x1=p1.x,x2=p2.x,x3=p3.x,y1=p1.y,y2=p2.y,y3=p3.y;
l=x1*y2+x2*y3+x3*y1-y1*x2-y2*x3-y3*x1;
if (l==0) return 0;
if (l>0) return 1;
if (l<0) return 2;
}
int main()
{
cin>>n;	
for(j=0;j<n;j++)
{	
cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y>>v.x>>v.y;
k=0;
if (v.x!=0) {
	         t=(m-b.x)/(double)v.x;
	         if (t>k)k=t;
	         t=(m-a.x)/(double)v.x;
	         if (t>k)k=t;
			 t=(-m-b.x)/(double)v.x;
	         if (t>k)k=t;
	         t=(-m-a.x)/(double)v.x;
	         if (t>k)k=t;
		    }	
if (v.y!=0) {
	         t=(m-b.y)/(double)v.y;
	         if (t>k)k=t;
	         t=(m-a.y)/(double)v.y;
	         if (t>k)k=t;
			 t=(-m-b.y)/(double)v.y;
	         if (t>k)k=t;
	         t=(-m-a.y)/(double)v.y;
	         if (t>k)k=t;
		    }
p.x=a.x+(int)(v.x*k);
p.y=a.y+(int)(v.y*k);
q.x=b.x+(int)(v.x*k);
q.y=b.y+(int)(v.y*k);
//cout<<"p("<<p.x<<","<<p.y<<") q("<<q.x<<","<<q.y<<")\n";
out=0;
mas[0]=ccw(a,c,p);
mas[1]=ccw(b,c,a);
mas[2]=ccw(q,c,b);
sort(mas,mas+3);
/*for(i=0;i<3;i++)cout<<mas[i]<<" ";
cout<<endl;*/
if ((mas[0]==0&&mas[1]==mas[2])||
    (mas[0]==mas[1]&&mas[1]==mas[2])||
    (mas[0]==0&&mas[1]==0)) out=1;
mas[0]=ccw(a,d,p);
mas[1]=ccw(b,d,a);
mas[2]=ccw(q,d,b);
sort(mas,mas+3);
/*for(i=0;i<3;i++)cout<<mas[i]<<" ";
cout<<endl;*/
if ((mas[0]==0&&mas[1]==mas[2])||
    (mas[0]==mas[1]&&mas[1]==mas[2])||
    (mas[0]==0&&mas[1]==0)) out=1;
cout<<out;
}
cout<<endl;	
//system("pause");
return 0;
}
