#include<bits/stdc++.h>

using namespace std;
#define eps = (1e-10);
//点
struct Point{
    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 norm(){return x*x+y*y;}//模的平方
    double ABS() {return sqrt(norm());}//模
};
//线段
struct Segment{
    Point p1,p2;
};
//点积
double dot(Point a,Point b){
    return a.x*b.x+a.y*b.y;
}
//叉积
double cross(Point a,Point b){
    return a.x*b.y-a.y*b.x;
}
bool Intersect(Segment A ,Segment B){
    if(max(B.p1.x,B.p2.x)<min(A.p1.x,A.p2.x)) return 0;
    if(max(B.p1.y,B.p2.y)<min(A.p1.y,A.p2.y)) return 0;
    if(max(A.p1.y,A.p2.y)<min(B.p1.y,B.p2.y)) return 0;
    if(max(A.p1.x,A.p2.x)<min(B.p1.x,B.p2.x)) return 0;
    if(cross(A.p1-B.p1,A.p2-B.p1)*cross(A.p1-B.p2,A.p2-B.p2)>0) return 0;
    if(cross(B.p1-A.p1,B.p2-A.p1)*cross(B.p1-A.p2,B.p2-A.p2)>0) return 0;
    return 1;
}
int main(){
    int q;
    scanf("%d",&q);
    while(q--){
        Segment A,B;
        scanf("%lf %lf %lf %lf",&A.p1.x,&A.p1.y,&A.p2.x,&A.p2.y);
        scanf("%lf %lf %lf %lf",&B.p1.x,&B.p1.y,&B.p2.x,&B.p2.y);
        if(Intersect(A,B)){
            puts("1");
        }else{
            puts("0");
        }
    }
    return 0;
}
