#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;
}

// Orthogonal
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);
}

// Orthogonal
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);
}

// ???????????¢
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);
}

// ????????¨??????????????¢
// TODO

int Q;

int main() {

	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;
	}
}

Measured memory_bytes: 3208