#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
using namespace std;

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(x*a, y*a); }
    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 {
	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 {
    Point p0, p1;
};

typedef Segment Line;

double dot(Vector a, Vector b) {
    return a.x*b.x + a.y*b.y;
}

double norm(Vector a) {
    return a.x*a.x + a.y*a.y;
}

double abs(Vector a){
    return sqrt(norm(a));
}

/*
  ???????????§??????????????¨??????????????°??????
  |a*b|=|a||b|sin(theta)
 */
double cross(Vector a, Vector b){ 
    return a.x*b.y - a.y*b.x;
}

/*const?????????????????????????????????*/
const int COUNTER_CLOCKWISE = 1;
const int CLOCKWISE = -1;
const int ON_SEGMENT = 0;
const int ONLINE_FRONT = -2;
const int ONLINE_BACK = 2;

int ccw(Point p0, Point p1, Point p2){
    if (cross(p1-p0, p2-p0) > EPS) return COUNTER_CLOCKWISE;
    else if (cross(p1-p0, p2-p0) < -EPS) return CLOCKWISE;
    else if (dot(p1-p0,p2-p0) < -EPS) return ONLINE_BACK;
    else if (norm(p1-p0) < norm(p2-p0)) return ONLINE_FRONT;
    else return ON_SEGMENT;
}

/*
  intersect
  ?????¨?????????????????¢???????????£????????????????????????
  ????????????????¨?????????????????¨???????????????????????????°OK
*/
bool intersect(Point p0, Point p1, Point p2, Point p3) {
    return ((ccw(p0,p1, p2) * ccw(p0,p1,p3) <= 0) && (ccw(p2, p3, p0) * ccw(p2,p3,p1) <=0));
}

int main() {
    int n,i,d;
    
    Point p0, p1, p2,p3;
    cin >> n;
    for(i=0;i<n;i++){
	cin >>  p0.x>> p0.y>>p1.x>>p1.y>>p2.x>>p2.y>>p3.x>>p3.y;
	if (intersect(p0,p1,p2,p3)) cout << "1" << endl;
	else cout << "0" << endl;
    }
    return 0;

}