#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);

#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)

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 {
		// first x, second y
		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;

struct Segment{
public:
	Point p1, p2;
	Segment(Point p1, Point p2){
		this->p1 = p1;
		this->p2 = p2;
	}
};

// ??????
double dot(Vector a, Vector b){
	//|a||b|cos(theta)
	return a.x * b.x + a.y * b.y;
}

// ??????
double cross(Vector a, Vector b){
	//|a||b|cos(theta)
	return a.x * b.y - a.y * b.x;
}

// ??´?????????
bool isOrthogonal(Vector a, Vector b){
	return equals(dot(a, b), 0.0);
}
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2){
	return isOrthogonal(a1 - a2, b1- b2);
}

// ????????????
bool isParallel(Vector a, Vector b){
	return equals(cross(a, b), 0.0);
}
bool isParallel(Point a1, Point a2, Point b1, Point b2){
	return isParallel(a1 - a2, b1- b2);
}

// ???p????????????s???????????????????????????
Point project(Segment s, Point p){
	// ??\??????????????????
	// hypo -> p - p1, base -> p2 - p1
	// t = |hypo|cos??
	// cos?? = dot(hypo,base)/|hypo||base|
	// project = s.p1 + base/|base| * t
	Vector hypo = p - s.p1;
	Vector base = s.p2 - s.p1;
	double r = dot(hypo, base) / base.norm();
	return s.p1 + base * r;
}

// ???p????????????s???????§°?????¨?????????
Point reflection(Segment s, Point p){
	Point pr = project(s, p);
	return p + (pr - p) * 2.0;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

// p0??????p1????????????????????????????????????p2?????????
int ccw(Point p0, Point p1, Point p2){
	Vector a = p1 - p0;
	Vector b = p2 - p0;
	if( cross(a, b) > EPS) return COUNTER_CLOCKWISE;
	if( cross(a, b) < -EPS) return CLOCKWISE;
	if (dot(a,b) <-EPS) return ONLINE_BACK;
	if (a.norm() < b.norm()) return ONLINE_FRONT;
	return ON_SEGMENT;
}

// ????????????????????? ??????p1->p2, p3->p4
bool intersect(Point p1, Point p2, Point p3, Point p4){
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
            ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}

// ?????????????????????
bool intersect(Segment s1, Segment s2){
    return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

// ???????????????
Point crosspoint(Segment s1, Segment s2){
	// s1.p1??????s2???????????????????????????d1
	// s1.p2??????s2???????????????????????????d2??¨????????¨???
	// ?????????s1???d1/(d1+d2)?????????????????¨??????
	Vector base = s2.p2 - s2.p1;
	Vector hypo1 = s1.p1 - s2.p1;
	Vector hypo2 = s1.p2 - s2.p1;
	double d1 = abs(cross(base, hypo1)) / base.abs();
	double d2 = abs(cross(base, hypo2)) / base.abs();
	double t = d1 / (d1 + d2);
	return s1.p1 + (s1.p2 - s1.p1) * t;
}

// ???????????¢
double distance(Point a, Point b){
	return (a - b).abs();
}

// ?????¨??´???????????¢
double distanceLinePoint(Segment s, Point p){
	// sin?? = |cross(hypo, base)|/|hypo||base|
	// distance = |hypo|sin?? = |cross(hypo, base)|/|base|
	Vector hypo = p - s.p1;
	Vector base = s.p2 - s.p1;
	return abs(cross(hypo, base)) / base.abs();
}

// ?????¨??????????????¢
double distanceSegmentPoint(Segment s, Point p){
	// (p2-p1)??¨???p-p1??????90???????????§????????´??????p??¨p1????????¢
	// (p1-p2)??¨???p-p2??????90???????????§????????´??????p??¨p2????????¢
	// ????????\????????´???????????¨??´???????????¢
	if(dot(s.p2-s.p1, p-s.p1) < 0.0) return (p - s.p1).abs();
	if(dot(s.p1-s.p2, p-s.p2) < 0.0) return (p - s.p2).abs();
	return distanceLinePoint(s, p);
}

// ????????¨??????????????¢
double distanceSegmentSegment(Segment s1, Segment s2){
	if(intersect(s1, s2)) return 0.0;
	double ret = distanceSegmentPoint(s1, s2.p1);
	ret = min(ret, distanceSegmentPoint(s1, s2.p2));
	ret = min(ret, distanceSegmentPoint(s2, s1.p1));
	ret = min(ret, distanceSegmentPoint(s2, s1.p2));
	return ret;
}


class Answer{
public:
	static void CGL_1_A() {
		int Q;
		Point p1, p2;
		cin >> p1.x >> p1.y >> p2.x >> p2.y;
		cin >> Q;
		rep(i, Q){
			Point pp;
			cin >> pp.x >> pp.y;
			Point pr = project(Segment(p1, p2), pp);
			fprintf(stdout, "%.10f %.10f\n", pr.x, pr.y);
		}
	}
	static void CGL_1_B() {
		int Q;
		Point p1, p2;
		cin >> p1.x >> p1.y >> p2.x >> p2.y;
		cin >> Q;
		rep(i, Q){
			Point pp;
			cin >> pp.x >> pp.y;
			Point rf = reflection(Segment(p1, p2), pp);
			fprintf(stdout, "%.10f %.10f\n", rf.x, rf.y);
		}
	}
	static void CGL_1_C() {
		int Q;
		Point p0, p1;
		cin >> p0.x >> p0.y >> p1.x >> p1.y;
		cin >> Q;
		rep(i, Q){
			Point p2;
			cin >> p2.x >> p2.y;
			int c = ccw(p0, p1, p2);
			if(c == COUNTER_CLOCKWISE) cout << "COUNTER_CLOCKWISE" << endl;
			if(c == CLOCKWISE) cout << "CLOCKWISE" << endl;
			if(c == ONLINE_BACK) cout << "ONLINE_BACK" << endl;
			if(c == ONLINE_FRONT) cout << "ONLINE_FRONT" << endl;
			if(c == ON_SEGMENT) cout << "ON_SEGMENT" << endl;
		}
	}
	static void CGL_2_A() {
		int Q;
		cin >> Q;
		rep(i, Q){
			Point p0, p1, p2, p3;
			cin >> p0.x >> p0.y;
			cin >> p1.x >> p1.y;
			cin >> p2.x >> p2.y;
			cin >> p3.x >> p3.y;
			int r;
			if(isOrthogonal(p0,p1,p2,p3)) {r = 1;}
			else if(isParallel(p0,p1,p2,p3)){r = 2;}
			else{r = 0;}
			cout << r << endl;
		}
	}
	static void CGL_2_B() {
		int Q;
		cin >> Q;
		rep(i, Q){
			Point p0, p1;
			cin >> p0.x >> p0.y >> p1.x >> p1.y;
			Point p2, p3;
			cin >> p2.x >> p2.y >> p3.x >> p3.y;
			cout << (intersect(p0, p1, p2, p3) ? 1 : 0) << endl;
		}
	}
	static void CGL_2_C() {
		int Q;
		cin >> Q;
		rep(i, Q){
			Point p0, p1;
			cin >> p0.x >> p0.y >> p1.x >> p1.y;
			Point p2, p3;
			cin >> p2.x >> p2.y >> p3.x >> p3.y;
			Point c = crosspoint(Segment(p0, p1), Segment(p2, p3));
			fprintf(stdout, "%.10f %.10f\n", c.x, c.y);
		}
	}

	static void CGL_2_D(){
		int Q;
		cin >> Q;
		rep(i, Q){
			Point p0, p1;
			cin >> p0.x >> p0.y >> p1.x >> p1.y;
			Point p2, p3;
			cin >> p2.x >> p2.y >> p3.x >> p3.y;
			double ret = distanceSegmentSegment(Segment(p0, p1), Segment(p2, p3));
			fprintf(stdout, "%.10f\n", ret) ;
		}
	}
};

int main() {
	Answer::CGL_2_B();
}

Measured memory_bytes: 3220