#include <bits/stdc++.h>
using namespace std;

using coord = long double;
const long double pi = acos(-1);
const long double EPS = 1e-8;

int sign(coord x) { return (x > EPS) - (x < -EPS); }
coord sq(coord x) { return x * x; }

struct point {
	coord x, y;
	point() : x(0), y(0) {} point(coord _x, coord _y): x(_x), y(_y) {}
	inline point operator+(point& p){ return {x + p.x, y + p.y}; }
	inline point operator-(point& p){ return {x - p.x, y - p.y}; }
	inline point operator*(coord o){ return {x * o, y * o}; }
	inline point operator/(coord o){ return {x / o, y / o}; }
	inline void operator=(point& p){ x = p.x, y = p.y; }
	inline bool operator==(point& p){return sign(x - p.x) == 0 and sign(y - p.y) == 0; }

	inline coord operator*(point p){ return x * p.x + y * p.y; } // |a||b|cos(thta)
	inline coord operator^(point p){ return x * p.y - y * p.x; } // |a||b|sin(thta)

	inline int ccw(point p){ return sign(*this ^ p); } // ccw  -1 left, 0 over, 1 right

	inline long double norm(){ return hypot(x, y); }
	inline coord norm2(){ return x * x + y * y; }

	inline point rot90(){return {-y, x}; }
	inline point rot(long double ang){ return {cos(ang) * x - sin(ang) * y, sin(ang) * x + cos(ang) * y}; }

	inline void print(){ cout<<x<<' '<<y<<'\n'; }
};

struct line {
	point p; coord c; //p *<x,y> = c
	line() {} line(point _p, coord _c): p(_p), c(_c) {}
	line(point a, point b) : p((b - a).rot90()), c(p * a) {}
	inline line parll(point v){ return line(p, p * v); }// parallel line at point v
	inline line perp(){ return line(p.rot90(), c); }// perpendicular line

	bool contains(point v){ return sign(p * v - c) == 0; }
	bool intsec(line l){ return sign(p ^ l.p) != 0; } // can be the same line

	point get_intsec(line l){ coord d = p ^ l.p; 
		return point((c * l.p.y - l.c * p.y) / d, (p.x * l.c - c * l.p.x) / d ); }
	coord dist(point v){ return abs(p * v - c) / p.norm2(); }
};

struct segment {
	point a, b;
	segment() {} segment(point _a, point _b): a(_a), b(_b) {}

	bool contains(point p){return sign((p-a)^(b-a)) == 0 and sign((p-a)*(b-a)) >= 0 and sign((p-b)*(a-b)) >= 0;}
	
	int ccw(point p){ return((b - a).ccw(p)); } // ccw  -1 left, 0 over, 1 right  of seg a->b

	bool intsec(segment q){ segment p = *this;
		if (p.contains(q.a) or p.contains(q.b) or q.contains(p.a) or q.contains(p.b))
			return true;
		return p.ccw(q.a-p.a)*p.ccw(q.b-p.a) == -1 and q.ccw(p.a-q.a)*q.ccw(p.b-q.a) == -1;	
	}

	coord dist(segment q){segment p = *this; 
		return p.intsec(q)? 0 : min({p.dist(q.a), p.dist(q.b), q.dist(p.a), q.dist(p.b)});	}

	coord dist(point p){
		if (sign(((p - a) * (b - a))) >= 0 and sign((p - b) * (a - b)) >= 0)
			return abs((p - a) ^ (b - a)) / (b - a).norm();
		return min((p - a).norm(), (p - b).norm());
	}

	line getline(){return line(a, b); }

	segment getintsec(segment q){segment p = *this;
		if (((p.b - p.a)^(q.b - q.a)) == 0){
			if (p.contains(q.a) and q.contains(p.b))
				return segment(q.a, p.b);
			else if (p.contains(q.a) and p.contains(q.b))
				return q;
			else if (q.contains(p.a) and p.contains(q.b))
				return segment(p.a, q.b);
			return p;
		}	
		point r = (p.getline()).get_intsec(q.getline());
		return segment(r, r);
	}
};

int main(){
	int n;
	cin>>n;
	while (n--){
	int a, b, c, d;
	cin>>a>>b>>c>>d;
	segment p = segment(point(a, b), point(c, d));
	cin>>a>>b>>c>>d;
	segment q = segment(point(a, b), point(c, d));
	cout<<p.intsec(q)<<endl;
	}

	cout<<setprecision(9)<<fixed;

	// if (p.intsec(q) == 0)
	// 	cout<<"Empty"<<endl;
	// else{
	// 	segment w = p.getintsec(q);
	// 	(w.a).print();
	// 	if (!(w.a == w.b))
	// 		(w.b).print();
	// }
}


Measured memory_bytes: 3100