#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
class Point2D{
	T pos[2];
public:
	Point2D()=default;
	Point2D(T x,T y){
		pos[0]=x,pos[1]=y;
	}
	Point2D operator-(const Point2D& r){
		Point2D temp(*this);
		temp.pos[0] -= r.pos[0];
		temp.pos[1] -= r.pos[1];
		return temp;
	}
	T& operator[](int index){return pos[index];}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N=in();
	LOOP(N){
		Point2D<int> P[4];
		REP(i,4){
			P[i][0]=in();
			P[i][1]=in();
		}
		Point2D<double> v[2],u;
		REP(i,2){
			REP(j,2){
				v[i][j] = (P[2*i+1]-P[2*i])[j];
			}
			u[i] = P[2][i]-P[0][i];
		}

		auto cross = [](Point2D<double>& l,Point2D<double>& r){
			return l[0]*r[1]-l[1]*r[0];
		};

		if(abs(cross(v[0],v[1]))<=1e-10){
			Point2D<double> w;
			REP(i,2){
				w[i] = P[3][i]-P[0][i];
			}
			double nv[2],nu,nw;
			nv[0] = hypot(v[0][0],v[0][1]);
			nv[1] = hypot(v[1][0],v[1][1]);
			nu = hypot(u[0],u[1]);
			nw = hypot(w[0],w[1]);
			REP(i,2){
				v[0][i] /= nv[0];
				v[1][i] /= nv[1];
				//w[i] /= nw;
				//u[i] /= nu;
			}
			double k1,k2;
			k1 = v[0][0]*u[0]+v[0][1]*u[1];
			k2 = v[0][0]*w[0]+v[0][1]*w[1];

			if((nv[1]+nu>nw) && (nv[1]+nw>nu) && (nw+nu>nv[1])){
				out(0);
			}
			else if((0<=k1 && k1<=nv[0]) || (0<=k2 && k2<=nv[0]) || (0>=k1 && k2>=nv[0]) || (0>=k2 && k1>=nv[0])){
				out(1);
			}
			else out(0);
			continue;
		}
		double t1 = (cross(u,v[0]))/(cross(v[0],v[1]));
		double t2 = (cross(u,v[1]))/(cross(v[0],v[1]));
		if(0<=t1 && t1<=1 && 0<=t2 && t2<=1){
			out(1);
		}
		else{
			out(0);
		}
	}
	
	return 0;
}
