#include<complex>
#include<iostream>

using namespace std;


typedef complex<double> P;

// ?¨±?????????????????
#define EPS (1e-10)
// 2??????????????????????????????????????????
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2??????????????????????????????????????????
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )

// ?????? (dot product) : a???b = |a||b|cos??
double dot(P a, P b) {
	return (a.real() * b.real() + a.imag() * b.imag());
}

// ?????? (cross product) : a??b = |a||b|sin??
double cross(P a, P b) {
	return (a.real() * b.imag() - a.imag() * b.real());
}

int is_intersected_ls(P a1, P a2, P b1, P b2) {
	return (cross(a2 - a1, b1 - a1) * cross(a2 - a1, b2 - a1) < EPS) &&
		(cross(b2 - b1, a1 - b1) * cross(b2 - b1, a2 - b1) < EPS);
}

int main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		double x0, y0, x1, y1, x2, y2, x3, y3;
		cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		P p0(x0, y0), p1(x1, y1), p2(x2, y2), p3(x3, y3);
		cout << is_intersected_ls(p0, p1, p2, p3) << endl;
	}
}