// ConsoleApplication.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdio.h"
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <string>

using namespace std;
using NUM = long double;

template<typename T>
struct Point {
	T x, y;
	Point<T> operator+(const Point<T>& rhs)const {
		Point<T> p;
		p.x = this->x + rhs.x;
		p.y = this->y + rhs.y;
		return p;
	}
	Point<T> operator-(const Point<T>& rhs)const {
		Point<T> p;
		p.x = this->x - rhs.x;
		p.y = this->y - rhs.y;
		return p;
	}
	Point<T> operator*(const T rhs) const {
		Point<T> p;
		p.x = this->x * rhs;
		p.y = this->y * rhs;
		return p;
	}
	Point<T> operator-() const {
		Point<T> p;
		p.x = this->x * -1.0;
		p.y = this->y * -1.0;
		return p;
	}
};

template<typename T>
Point<T> operator*(const T val, const Point<T>& p)
{
	return p*val;
}

template<typename T>
struct Segment {
	Point<T> p1, p2;
};

template<typename T>
bool isZero(const T val)
{
	return fabs(val) < 1e-10;
}

template<typename T>
T innerProduct(const Point<T>& p0, const Point<T>& p1)
{
	double x0 = p0.x;
	double y0 = p0.y;
	double x1 = p1.x;
	double y1 = p1.y;
	return x0 * x1 + y0 * y1;
}

template<typename T>
T outerProduct(const Point<T>& p0, const Point<T>& p1)
{
	double x0 = p0.x;
	double y0 = p0.y;
	double x1 = p1.x;
	double y1 = p1.y;
	return x0 * y1 - y0 * x1;
}

template<typename T>
T norm(const Point<T>& p)
{
	double x = p.x;
	double y = p.y;
	return x*x + y*y;
}

template<typename T>
T absolute(const Point<T>& p)
{
	return sqrt(norm(p));
}

template<typename T>
void readPoint(Point<T>& p)
{
	cin >> p.x;
	cin >> p.y;
}

template<typename T>
void readSegment(Segment<T>& s)
{
	cin >> s.p1.x;
	cin >> s.p1.y;
	cin >> s.p2.x;
	cin >> s.p2.y;
}

//template<typename T>
//void outputComponentesOfPoint(const Point<T>& p)
//{
//	cout << fixed;
//	cout << setprecision(8) << p.x;
//	cout << " ";
//	cout << setprecision(8) << p.y;
//	cout << endl;
//}

//template<typename T>
//T getDistanceFromPointToLine(const Segment<T>& s, const Point<T>& p) {
//	const Point<T> a = p - s.p1;
//	const Point<T> b = s.p2 - s.p1;
//	const Point<T> outer = outerProduct(a, b);
//	return outer / absolute(b);
//}

//template<typename T>
//T distance(const Point<T>& p1, const Point<T>& p2)
//{
//	return absolute(p2 - p1);
//}
//
//template<typename T>
//T getDistanceFromPointToSegment(const Point<T>& p, const Segment<T>& s) {
//	const T zero = static_cast<T>(0);
//	const Point<T> a = p - s.p1;//本当は使いまわせる
//	const Point<T> b = s.p2 - s.p1;
//	const Point<T> c = p - s.p2;
//	const T innerAB = innerProduct(a, b);
//	const T innerc_b = innerProduct(c, -b);
//
//	T aaa = distance(p, s.p1);
//	T bbb = distance(p, s.p2);
//	T ccc = fabs(outerProduct(a, b) / absolute(b));
//	if (innerAB < zero) {
//		return distance(p, s.p1);
//	}
//	else if (innerc_b < zero) {
//		return distance(p, s.p2);
//	}
//	else {
//		return fabs(outerProduct(a, b) / absolute(b) );
//	}
//}
//

template<typename T>
double getParameterOfProjectedPointToSegment(const Point<T>& p, const Segment<T>& s)
{
	const Point<T> a = p - s.p1;
	const Point<T> b = s.p2 - s.p1;
	const T normB = norm(b);
	const T ab = innerProduct(a, b);
	return ab / normB;
}

template<typename T>
int getPositionOnSegment(const Point<T>& p, const Segment<T>& s)
{
	const T position = getParameterOfProjectedPointToSegment(p, s);
	if (position < 0.0) {
		return -1;
	}
	else if (1.0 < position) {
		return 1;
	}
	else {
		return 0;
	}
}

template<typename T>
bool intersects(const Segment<T>& s1, const Segment<T>& s2) {
	function<bool(Segment<T>, Segment<T>)> intersectsFromOneSegment//one segment : s1
		= [&](const Segment<T>& s1, const Segment<T>& s2) {
		const Point<T> a = s2.p1 - s1.p1;
		const Point<T> c = s2.p2 - s1.p1;
		const Point<T> b = s1.p2 - s1.p1;
		const T outerBA = outerProduct(b, a);
		const T outerBC = outerProduct(b, c);
		return  isZero(outerBA) || isZero(outerBC) || ( outerBA > 0.0 != outerBC > 0.0 );
	};

	bool isFourPointsOnSameLine = false; {
		const Point<T> a = s2.p1 - s1.p1;
		const Point<T> c = s2.p2 - s1.p1;
		const Point<T> b = s1.p2 - s1.p1;
		const T outerBA = outerProduct(b, a);
		const T outerBC = outerProduct(b, c);
		isFourPointsOnSameLine = isZero(outerBA) && isZero(outerBC);
	}
	if (isFourPointsOnSameLine) {//case of all of four Points is on same line
		return getPositionOnSegment(s2.p1, s1) * getPositionOnSegment(s2.p2, s1) <= 0;
	}
	else {
		return intersectsFromOneSegment(s1, s2) && intersectsFromOneSegment(s2, s1);
	}
	
}
//
//template<typename T>
//T getDistanceFromSegmentToSegment(const Segment<T>& s1, const Segment<T>& s2) {
//	if (intersects(s1, s2)) {
//		return static_cast<T>(0.0);
//	}else{
//		return min(
//			min(getDistanceFromPointToSegment(s1.p1, s2), getDistanceFromPointToSegment(s1.p2, s2))
//			, min(getDistanceFromPointToSegment(s2.p1, s1), getDistanceFromPointToSegment(s2.p2, s1))
//		);
//	}
//}

//template<typename T>
//void projectPointToSegment(const Point<T>& p, const Segment<T>& s, Point<T>& foot, T& param )
//{
//	const Point<T> a = p - s.p1;
//	const Point<T> b = s.p2 - s.p1;
//	const T normB = norm(b);
//	const T ab = innerProduct(a, b);
//	param = ab / normB;
//	foot = s.p1 + (s.p2 - s.p1)*param;
//}



int main()
{
	int q; cin >> q;
	for (int i = 0; i != q; ++i) {
		Segment<NUM> s1, s2;
		readSegment(s1);
		readSegment(s2);
		cout << (intersects(s1, s2) ? 1 : 0) << endl;
	}

	return 0;
}


Measured memory_bytes: 3220