#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;

#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 k){
        return Point(x * k, y * k);
    }

    Point operator/ (double k){
        return Point(x / k, y / k);
    }

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

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

    bool operator == (const Point &p) const{
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
};

typedef Point Vector;

class Seg{
public:
    Point p1;
    Point p2;
    Seg(Point p1_, Point p2_){
        p1 = p1_;
        p2 = p2_;
    }
};

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

double cross(Vector a, Vector b){
    return a.x * b.y - a.y * b.x;
}

bool isParallel(Vector a, Vector b){
    return equals(cross(a, b), 0.0);
}

bool isOrthogonal(Vector a, Vector b){
    return equals(dot(a, b), 0.0);
}
;
double getCos(Vector a, Vector b){
    return dot(a, b) / (a.abs() * b.abs());
}

double dist(Point p1, Point p2){
    return sqrt(pow((p1.x - p2.x), 2) + pow((p1.y - p2.y), 2));
}

Point project(Seg s, Point p0){
    if(s.p1 == p0){
        return p0;
    }
    if(s.p2 == p0){
        return p0;
    }
    return s.p1 + (s.p2 - s.p1) / (s.p2 - s.p1).abs() * (p0 - s.p1).abs() * getCos(s.p2 - s.p1, p0 - s.p1);
}

Point reflect(Seg s, Point p0){
    Point p = project(s, p0);
    return p0 + (p - p0) * 2;
}


#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0

int counterClockwise(Point p0, Point p1, Point p2){
    Vector v1 = p1 - p0;
    Vector v2 = p2 - p0;
    if(cross(v1, v2) > EPS) return COUNTER_CLOCKWISE;
    if(cross(v1, v2) < -EPS) return CLOCKWISE;
    if(dot(v1, v2) < -EPS) return ONLINE_BACK;
    if(v1.norm() < v2.norm()) return ONLINE_FRONT;
    return ON_SEGMENT;
}

bool intersect(Seg s1, Seg s2){
    int t1 = counterClockwise(s1.p1, s1.p2, s2.p1);
    int t2 = counterClockwise(s1.p1, s1.p2, s2.p2);
    int t3 = counterClockwise(s2.p1, s2.p2, s1.p1);
    int t4 = counterClockwise(s2.p1, s2.p2, s1.p2);
    if(t1 * t2 <= 0){
        if(t3 * t4 <= 0){
            return true;
        }
    }
    return false;
}

double getDistanceSP(Seg s, Point p0){
    if(dot(s.p2 - s.p1, p0 - s.p1) < 0.0) return (p0 - s.p1).abs();
    if(dot(s.p1 - s.p2, p0 - s.p2) < 0.0) return (p0 - s.p2).abs();
    return (project(s, p0) -  p0).abs();
}

double getDistance(Seg s1, Seg s2){
    if(intersect(s1, s2)){
        return 0.0;
    }
    return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)),
                min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));
}

int main(){
    int q;
    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        int xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3;
        scanf("%d", &xp0);
        scanf("%d", &yp0);
        scanf("%d", &xp1);
        scanf("%d", &yp1);
        scanf("%d", &xp2);
        scanf("%d", &yp2);
        scanf("%d", &xp3);
        scanf("%d", &yp3);
        
        Seg s1 = Seg(Point(xp0, yp0), Point(xp1, yp1));
        Seg s2 = Seg(Point(xp2, yp2), Point(xp3, yp3));

        if(intersect(s1, s2)){
            printf("1\n");
        }else{
            printf("0\n");
        }
    }
}

/*
int main(){
    int q;
    scanf("%d", &q);

    for(int i = 0; i < q; i++){
        int xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3;
        scanf("%d", &xp0);
        scanf("%d", &yp0);
        scanf("%d", &xp1);
        scanf("%d", &yp1);
        scanf("%d", &xp2);
        scanf("%d", &yp2);
        scanf("%d", &xp3);
        scanf("%d", &yp3);

        printf("%.10f\n", getDistance(Point(xp0, yp0), Point(xp1, yp1), Point(xp2, yp2), Point(xp3, yp3)));
    }

}
*/




Measured memory_bytes: 3164