#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

struct point{
	double x,y;
	point operator+(point p){
		return point{x+p.x,y+p.y};
	}
	point operator-(point p){
		return point{x-p.x,y-p.y};
	}
	point operator*(double p){
	return point{x*p,y*p};
	}
	point operator/(double p){
		if(!p) return point{0,0}; 
		return point{x/p,y/p};
	}
	bool operator==(point p){
		return fabs(x-p.x)<eps&&fabs(y-p.y)<eps;
	}
};

typedef pair<point,point> pp;
const point O{0,0};

class Geom{
	public:
	double Length(point x,point y){
		point z=y-x;
		return sqrt(z.x*z.x+z.y*z.y);
	}
	double IP(point p,point q){
		return p.x*q.x+p.y*q.y;
	}
	double CP(point p,point q){
		return p.x*q.y-q.x*p.y;
	}
	string Counter_Clockwise(pp a,point x){
		point A=a.second-a.first;
		point X=x-a.first;
		double ip=IP(A,X),cp=CP(A,X),Al=Length(O,A),Xl=Length(O,X);
		if(cp>eps) return "Counter_Clockwise";
		if(cp<-eps) return "Clockwise";
		if(ip<-eps) return "Online_Back";
		if(Xl<Al||fabs(Xl-Al)<eps) return "On_Segment";
		return "Online_Front";
	}
	string Parallel_Orthogonal(pp a,pp b){
		point A=a.second-a.first,B=b.second-b.first;
		double ip=IP(A,B),cp=CP(A,B);
		string f=Counter_Clockwise(pp(a.first,a.second),b.first),s=Counter_Clockwise(pp(a.first,a.second),b.second);
		if(f[0]!='C'&&s[0]!='C') return "Agreement";
		if(cp<eps&&cp>-eps) return "Parallel";
		if(ip<eps&&ip>-eps) return "Orthogonal";
		else return "Commonly";
	}
	string Intersection(pp a,pp b){
		point p=Cross_Point(a,b);
		if(p==point{inf,0}) return "not_Intersection";
		if(p==point{inf,inf}){
			string S=Counter_Clockwise(a,b.first),T=Counter_Clockwise(a,b.second);
			if(S==T&&S[2]=='l'&&T[2]=='l') return "not_Intersection";
			return "Intersection";
		}
		string s=Counter_Clockwise(a,p),t=Counter_Clockwise(b,p);
		if(s[3]=='S'&&t[3]=='S') return "Intersection";
		else return "not_Intersection";
	}
	point Inter(pp  a,double x,double y){
		return (a.first*y+a.second*x)/(x+y);
	}
	point Exterior(pp a,double x,double y){
		return (a.first*-y+a.second*x)/(x-y);
	}
	point Projection(pp a,point x){
		point A=x-a.first,B=a.second-a.first;
		double l=Length(O,B);
		return B*IP(A,B)/(l*l)+a.first;
	}
	point Cross_Point(pp a,pp b){
		string s=Parallel_Orthogonal(a,b);
		if(s[0]=='A') return point{inf,inf};
		if(s[0]=='P') return point{inf,0};
		point p=Projection(a,b.first),q=Projection(a,b.second);
		double pl=Length(b.first,p),ql=Length(b.second,q);
		string S=Counter_Clockwise(a,b.first),T=Counter_Clockwise(a,b.second);
		if(S==T) return Exterior(b,pl,ql);
		else return Inter(b,pl,ql);
	}
	void Point_in(point& p){
		cin>>p.x>>p.y;
	}
	void Point_out(point p){
		cout<<p.x<<' '<<p.y<<endl;
	}
};

int Q;
vector<point> p(4);

int main(){
	cout<<syosu(10);
	Geom geo;
	cin>>Q;
	for(int i=0;i<Q;i++){
		for(int j=0;j<4;j++) geo.Point_in(p[j]);
		string ans=geo.Intersection(pp(p[0],p[1]),pp(p[2],p[3]));
		if(ans=="Intersection") cout<<1<<endl;
		else cout<<0<<endl;
	}
}

Measured memory_bytes: 1252