#include <bits/stdc++.h>

using namespace std;

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

typedef complex<double> point;
struct segment { point p, q; };

double dot(point a, point b) { return real(conj(a) * b); }

double cross(point a, point b) { return imag(conj(a) * b); }

double area2(point a, point b, point c) { return cross(b - a, c - a); }

int ccw(point a, point b, point c)
{
	b -= a; c -= a;
	if (cross(b, c) > 0) return +1; // counter clockwise
	if (cross(b, c) < 0) return -1; // clockwise
	if (dot(b, c) < 0) return 
	+2; // c--a--b on line
	if (dot(b, b) < dot(c, c)) return -2; // a--b--c on line
	return 0;
}

bool intersectSS(const segment &s, const segment &t)
{
	return ccw(s.p, s.q, t.p) * ccw(s.p, s.q, t.q) <= 0 &&
			ccw(t.p, t.q, s.p) * ccw(t.p, t.q, s.q) <= 0;
}

point read(){
	double x, y; cin >> x >> y;
	return point(x, y);
}

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

	int n; cin >> n;
	for (int i = 0; i < n; ++i){
		point p = read(), q = read();
		segment s1 = {p, q};
		p = read(), q = read();
		segment s2 = {p, q};
		if (intersectSS(s1, s2)) cout << 1 << endl;
		else cout << 0 << endl;
	}

	return 0;
}