#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
using namespace std;


#define REP(i,n) for(int i=0;i<(int)n;i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()


double EPS = 1e-10;

double add(double a, double b){
	if(abs(a+b) < EPS * (abs(a) + abs(b))) return 0;
	return a+b;
}

struct P{
	double x,y;
	P(){}
	P(double x, double y) : x(x), y(y){
	}
	P operator +(P p){
		return P(add(x,p.x), add(y,p.y));
	}
	P operator -(P p){
		return P(add(x,-p.x), add(y,-p.y));
	}
	P operator *(double d){
		return P(d*x, d*y);
	}
	double dot (P p){
		return add(x*p.x, y*p.y);
	}
	double det (P p){
		return add(x*p.y, -y*p.x);
	}
	void print (){
		cout << x << " " << y <<endl;
		return;
	}
};

int onCheck(P &p, P &q, P &r){
	bool a = ((q-p).det(r-p)==0);
	bool b = ((p-q).dot(r-q) >=0 );
	bool c = ((p-r).dot(q-r)  >= 0 );
	if(a&&b&&c){
		return 1;
	}else{
		return 0;
	}
}

int intersectionCheck(P &p0, P &p1, P &p2, P &p3){
	P q0 = p1-p0;
	P q1 = p3-p2;
	if(q0.det(q1)==0){
		bool a =onCheck(p0,p2, p3) ;
		bool b =onCheck(p1,p2, p3) ;
		bool c = onCheck(p2,p0, p1) ;
		bool d = onCheck(p3,p0, p1);
		if (!a && !b && !c && !d){
			return 0;
		}else{
			return 1;
		}
	}

	P r = p0 + (p1-p0)*(q1.det(p2-p0)/q1.det(q0));
	bool e = onCheck(r, p0, p1);
	bool f = onCheck(r, p2, p3);
	if(e && f){
		return 1;
	}else{
		return 0;
	}
}

/*
int intersectionCheck(P &p0, P &p1, P &p2, P &p3){
	P q0 = p1-p0;
	P q1 = p3-p2;
	if(q0.det(q1)==0){
		if((p2-p1).det(p2-p0)!=0) return 0;
		if(((p2-p0).dot(p2-p1)<=0)||((p3-p0).dot(p3-p1)<=0) || ((p1-p2).dot(p1-p3)<=0)){
			return 1;
		}else{
			return 0;
		}
	}

	P r = p0 + (p1-p0)*(q1.det(p2-p0)/q1.det(q0));
	if ((p0-r).dot(p1-r) <=0 && (p2-r).dot(p3-r) <=0){
		return 1;
	} else{
		return 0;
	}
}
*/

int main(){
	int q;
	cin >> q;

	REP(i, q){
		P p0, p1, p2, p3;
		cin >> p0.x >> p0.y >>p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y ;
		cout << intersectionCheck(p0, p1, p2, p3) << endl;
	}
	return 0;
}