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

struct F {
	long long a, b;
	F() {}
	F(long long _a, long long _b) : a(_a), b(_b) {}
	F operator + (const F &f) {
		long long x = a * f.a, y = b * f.a + a * f.b;
		long long g = __gcd(x, y);
		return F(x / g, y / g);
	}
	F operator - (const F &f) {
		long long x = a * f.a, y = b * f.a - a * f.b;
		long long g = __gcd(x, y);
		return F(x / g, y / g);
	}
	F operator * (const F &f) {
		long long x = a * f.a, y = b * f.b;
		long long g = __gcd(x, y);
		return F(x / g, y / g);
	}
	F operator / (const F &f) {
		long long x = a * f.b, y = b * f.a;
		long long g = __gcd(x, y);
		return F(x / g, y / g);
	}
};
const double pi = acos(-1);
const double eps = 1e-8;
inline int sign(double a) {
	return a < -eps ? -1 : a > eps;
}
inline int cmp(double a, double b) {
	return sign(a - b);
}
double add(double a, double b) {
	if (abs(a + b) < eps * (abs(a) + abs(b))) return 0;
	return a + b;
}
typedef long long data;
struct P {
	data x, y;
	P() {}
	P(data x, data y) : x(x), y(y) {}
	P operator + (const P &p) { return P(x + p.x, y + p.y); }
	P operator - (const P &p) { return P(x - p.x, y - p.y); }
	P operator * (data d) { return P(x * d, y * d); }
	P operator / (data d) { return P(x / d, y / d); }
	data dot(const P &p) { return x * p.x + y * p.y; }
	data det(const P &p) { return x * p.y - y * p.x; }
	data disto(const P &p) { return (*this - p).abs(); }
	data alpha() { return atan2(y, x); }
	data abs() { return sqrt(abs2()); }
	data abs2() { return x * x + y * y; }
	P rot90() { P(-y, x); }
	P unit() { return *this / abs(); }
	bool operator < (P p) const {
		int c = cmp(x, p.x);
		if (c) return c == -1;
		return cmp(y, p.y) == -1;
	}
	friend istream& operator>>(istream &in, P &p) {
		in >> p.x >> p.y;
		return in;
	}
	friend ostream& operator<<(ostream& out, P &p) {
		out << p.x << ' ' << p.y;
		return out;
	}
};
P projection(P p1, P p2, P q) {
	P dir = p2 - p1;
	return p1 + dir * (dir.dot(q - p1) / dir.abs2());
}
P reflection(P p1, P p2, P q) {
	return projection(p1, p2, q) * 2 - q;
}
bool is_midddle(data a, data m, data b) {
	return sign(a - m) == 0 || sign(b - m) == 0 || (a < m != b < m);
}
bool is_midddle(P a, P m, P b) {
	return is_midddle(a.x, m.x, b.x) && is_midddle(a.y, m.y, b.y);
}
bool on_seg(P p1, P p2, P q) {
	return (p1 - q).det(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0;
	// return (p1 - q).det(p2 - q) == 0 && is_middle(p1, q, p2);
}
P intersection(P p1, P p2, P q1, P q2) {
	return p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / (q2 - q1).det(p2 - p1));
}
bool intersect(data l1, data r1, data l2, data r2) {
	if(l1 > r1) swap(l1, r1);
	if(l2 > r2) swap(l2, r2);
	return cmp(r1, l2) != -1 && cmp(r2, l1) != -1;
}
bool intersect(P p1, P p2, P q1, P q2) {
	return intersect(p1.x, p2.x, q1.x, q2.x) && intersect(p1.y, p2.y, q1.y, q2.y)
	&& (p1 - q1).det(p2 - q1) * (p1 - q2).det(p2 - q2) <= 0
	&& (q1 - p1).det(q2 - p1) * (q1 - p2).det(q2 - p2) <= 0;
}

int main() {
#ifdef LOCAL_DEFINE
	//freopen("data.in", "rt", stdin);
	//freopen("data.out", "w", stdout);
	auto _start = chrono::high_resolution_clock::now();
#endif

	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	int q;
	cin >> q;
	while (q--) {
		P p0, p1, p2, p3;
		cin >> p0 >> p1 >> p2 >> p3;
		cout << intersect(p0, p1, p2, p3) << '\n';
	}

#ifdef LOCAL_DEFINE
	auto _end = chrono::high_resolution_clock::now();
	cerr << "elapsed time: " << chrono::duration<double, milli>(_end - _start).count() << " ms\n";
#endif
	return 0;
}


Measured memory_bytes: 3220