#include<bits/stdc++.h>
#define lb long double
#define eps 1e-9
using namespace std;
struct Po{lb x,y;}p1,p2,q1,q2;
int t;
void get(Po &x){scanf("%Lf %Lf",&x.x,&x.y);}
Po operator -(Po x,Po y){return (Po){x.x-y.x,x.y-y.y};}
lb operator *(Po x,Po y){return x.x*y.y-x.y*y.x;}
bool onsegment(Po x,Po y,Po z){
	if (x.x>y.x) swap(x,y);
	if (z.x<x.x-eps||z.x>y.x+eps) return 0;
	if (x.y>y.y) swap(x,y);
	if (z.y<x.y-eps||z.y>y.y+eps) return 0;
	return 1;
}
int main(){
	scanf("%d",&t);
	while (t--){
		get(p1);get(p2);get(q1);get(q2);
		lb d1=(p2-p1)*(q1-p1),d2=(p2-p1)*(q2-p1),d3=(q2-q1)*(p1-q1),d4=(q2-q1)*(p2-q1);
		if (d1*d2<-eps&&d3*d4<eps){puts("1");continue;}
		if (fabs(d1)<eps&&onsegment(p1,p2,q1)){puts("1");continue;}
		if (fabs(d2)<eps&&onsegment(p1,p2,q2)){puts("1");continue;}
		if (fabs(d3)<eps&&onsegment(q1,q2,p1)){puts("1");continue;}
		if (fabs(d4)<eps&&onsegment(q1,q2,p2)){puts("1");continue;}
		puts("0");
	}
	return 0;
}
