#include<iostream>
#include<iomanip>
#include<algorithm>
#include<fstream>
#define _USE_MATH_DEFINES
#include<math.h>
#define EPS (1e-5)
#define equals(a, b) (fabs((a) - (b)) < EPS )
//#define cout fout
//#define cin fin
#define CCW 1
#define YCW -1
#define ONB 3
#define ONF 4
#define ONS 0
using namespace std;

class Point {
public:
	double x, y;

	Point(double x = 0, double y = 0) :x(x), y(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 a) {
		return Point(a * x, a * y);
	}
	Point operator / (double a) {
		return Point(x / a, y / a);
	}

	double abs() {
		return sqrt(norm());
	}
	double norm() {
		return x * x + y * y;
	}

	bool operator < (const Point &p)const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p)const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};

typedef Point Vector;

#ifdef cin
ifstream fin("CGL_1_C-in29.txt");
#endif

#ifdef cout
ofstream fout("out.txt");
#endif

double dot(Vector a, Vector b);
double cross(Vector a, Vector b);
double getDistanceSP(Point p, Point p1, Point p2);
double angle(Vector a, Vector b);
bool doIntersect(Point p1, Point p2, Point p3, Point p4);
double getDistanceSS(Point p1, Point p2, Point p3, Point p4);
int clockwise(Point p0, Point p1, Point p2);

int main() {
    int i, q;
	double x0, x1, x2, x3, y0, y1, y2, y3;
	
	
	cin >> q;
	for (i = 0; i < q; i++) {
		cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		Point p0(x0, y0), p1(x1, y1), p2(x2, y2), p3(x3, y3);
		if (doIntersect(p0, p1, p2, p3))cout << 1 << endl;
		else cout << 0 << endl;
	}
#ifdef cin
	fin.close();
#endif

#ifdef cout
	fout.close();
#endif
	return 0;
}

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}

double getDistanceSP(Point p, Point p1, Point p2) {
	if (dot(p - p1, p2 - p1) < 0.0)return (p - p1).abs();
	else if (dot(p - p2, p1 - p2) < 0.0)return (p - p2).abs();
	else return  fabs(cross(p2 - p1, p - p1)) / (p2 - p1).abs();
}


double angle(Vector a, Vector b) {
	if (equals(dot(a, b), a.abs() * b.abs()))return 0.0;
	else if (equals(dot(a, b), (-1) * a.abs() * b.abs()))return M_PI;
	if (cross(a, b) > 0.0)return acos(dot(a, b) / a.abs() / b.abs());
	else return (-1) * acos(dot(a, b) / a.abs() / b.abs());
}

bool doIntersect(Point p1, Point p2, Point p3, Point p4) {
	if (clockwise(p1, p2, p3) *  clockwise(p1, p2, p4) * clockwise(p3, p4, p1) * clockwise(p3, p4, p1) == 0) {
		return true;
	} else if (-1 <= clockwise(p1, p2, p3) * clockwise(p1, p2, p4) && clockwise(p1, p2, p3) * clockwise(p1, p2, p4) <= 0 && -1 <= clockwise(p3, p4, p1) * clockwise(p3, p4, p2) && clockwise(p3, p4, p1) * clockwise(p3, p4, p2) <= 0) {
		return true;
	} else {
		return false;
	}
}

double getDistanceSS(Point p1, Point p2, Point p3, Point p4) {
	if (doIntersect(p1, p2, p3, p4))return 0;
	else return min({ getDistanceSP(p4, p1, p2), getDistanceSP(p3, p1, p2), getDistanceSP(p1, p3, p4), getDistanceSP(p2, p3, p4) });
}

int clockwise(Point p0, Point p1, Point p2) {
	if (p2 == p0 || p2 == p1) {
		//cout << "ON_SEGMENT" << endl;
		return ONS;
	} else if (angle(p1 - p0, p2 - p0) == 0.0) {
		if ((p1 - p0).norm() < (p2 - p0).norm()) {
			//cout << "ONLINE_FRONT" << endl;
			return ONF;
		} else {
			//cout << "ON_SEGMENT" << endl;
			return ONS;
		}
	} else if(angle(p1 - p0, p2 - p0) == M_PI){
		//cout << "ONLINE_BACK" << endl;
		return ONB;
	} else {
		if (angle(p1 - p0, p2 - p0) > 0.0) {
			//cout << "COUNTER_CLOCKWISE" << endl;
			return CCW;
		} else {
			//cout << "CLOCKWISE" << endl;
			return YCW;
		}
	}
}

Measured memory_bytes: 3536