#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define db double
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}

int const N=1e5+3;
int top,n,m,cnt,sta[N];
struct point{
	db x,y;
    point operator - (point A) const{return (point){x-A.x,y-A.y};}
    point operator + (point A) const{return (point){x+A.x,y+A.y};}
    void print(){printf("%.10lf %.10lf\n",x,y);}
}A,B,C,D,c[N],p1[N],p2[N];

point operator *(db x,point A){return (point){x*A.x,x*A.y};}
db CJ(point A,point B){return A.x*B.y-B.x*A.y;}//叉积 
db DJ(point A,point B){return A.x*B.x+A.y*B.y;}//点积 
db dis(point A){return sqrt(A.x*A.x+A.y*A.y);}//向量长度 
bool cmp(point A,point B){return (CJ(A,B)>0 || CJ(A,B)==0 && dis(A)<dis(B));}//按极角排序 
void Convex(point *A,int &n){//求凸包 
	for (int i=1;i<=n;i++)
	  if (A[i].y<A[1].y || A[i].y==A[1].y && A[i].x<A[1].x) swap(A[i],A[1]);
    point base=A[1];top=0;
	for (int i=1;i<=n;i++) A[i]=A[i]-base;
	sort(A+2,A+n+1,cmp);
	sta[++top]=1;
	for (int i=2;i<=n;sta[++top]=i,i++)
	  while (top>1 && CJ(A[i]-A[sta[top-1]],A[sta[top]]-A[sta[top-1]])>=0) top--;
	for (int i=1;i<=top;i++) A[i]=A[sta[i]]+base;
	n=top;A[n+1]=A[1];
}
void Minkowski(point A[],point B[]){//闵可夫斯基（凸包合并） 
	for (int i=1;i<=n;i++) p1[i]=A[i+1]-A[i];
	for (int i=1;i<=m;i++) p2[i]=B[i+1]-B[i];
	int i=1,j=1;c[cnt=1]=A[1]+B[1];
	while (i<=n && j<=m)
	  if (CJ(p1[i],p2[j])>=0) cnt++,c[cnt]=c[cnt-1]+p1[i++];
	  else cnt++,c[cnt]=c[cnt-1]+p2[j++];
	while (i<=n) cnt++,c[cnt]=c[cnt-1]+p1[i++];
	while (j<=m) cnt++,c[cnt]=c[cnt-1]+p2[j++];	
}
int check(point p){//判断一个点是否在凸包内 
	if (CJ(p,c[2])>0 || CJ(c[cnt],p)>0) return 0;
	int pos=lower_bound(c+1,c+cnt+1,p,cmp)-c-1;
	return CJ(c[pos%cnt+1]-c[pos],p-c[pos])>=0; 
}
point CGL_1_A(point A,point B,point C){//点在直线上的投影点
	db d=dis(B-A);
	return (A+(DJ(C-A,B-A)/d/d*(B-A)));
}
point CGL_1_B(point A,point B,point C){//点关于直线的对称点
	point P=CGL_1_A(A,B,C);
	return (C+2*(P-C));
}
int CGL_1_C(point A,point B,point C){//向量的位置关系(向量AC和向量AB) 
    if (CJ(B-A,C-A)>0) return 1;//逆时针 
    if (CJ(B-A,C-A)<0) return 2;//顺时针 
    if (DJ(C-A,B-A)<0) return 3;//方向相反
	if (dis(C-A)>dis(B-A)) return 4;//方向相同 AC>AB
	if (dis(C-A)<=dis(B-A)) return 5;//方向相同 AB>AC
}
int CGL_2_A(point A,point B,point C,point D){//判断直线平行、垂直
	if (CJ(B-A,D-C)==0) return 2;//平行 
	if (DJ(B-A,D-C)==0) return 1;//垂直 
	return 0;//相交 
}
int CGL_2_B(point A,point B,point C,point D){//判断线段是否有交
	if (min(A.x,B.x)>max(C.x,D.x) || min(C.x,D.x)>max(A.x,B.x) || min(A.y,B.y)>max(C.y,D.y) || min(C.y,D.y)>max(A.y,B.y)) return 0;//快速排斥实验(两个矩形是否相交)
	return CJ(B-A,C-A)*CJ(B-A,D-A)<=0 && CJ(D-C,A-C)*CJ(D-C,B-C)<=0;//跨立实验
}

signed main(){
	for (int q=read();q;q--){
		scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y,&D.x,&D.y);
		writeln(CGL_2_B(A,B,C,D));
	}
	return 0;
}


Measured memory_bytes: 3260