#include <bits/stdc++.h>

#define NIL -2
#define INF 1000000001
#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 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());}
    double dot(Point p){
        return x*p.x + y*p.y;
    }
    double prod(Point p){
        return x*p.y - y*p.x;
    }

    bool operator < (Point &p){
        return x != p.x ? x < p.x : y < p.y;
    }
    bool operator == (Point &p){
        return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
    }
  
};
typedef Point Vector;

int ccw(Point p0, Point p1,Point p2){
    Vector p10 = p1 - p0;
    Vector p20 = p2 - p0;
    double prod = p10.prod(p20);
    if(prod > EPS) return 1;
    if(prod < -EPS) return -1;
    if(p10.dot(p20) < -EPS) return 2;
    if(p10.abs() < p20.abs()) return -2;
    return 0; 
}

bool intersection(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(){
    double p0x,p0y,p1x,p1y;
    double p2x,p2y,p3x,p3y;
    int q;
    
    scanf("%d",&q);
    for(int i = 0;i < q;i++){
        scanf("%lf %lf %lf %lf",&p0x,&p0y,&p1x,&p1y);
        scanf("%lf %lf %lf %lf",&p2x,&p2y,&p3x,&p3y);
        Point p0(p0x,p0y);
        Point p1(p1x,p1y);
        Point p2(p2x,p2y);
        Point p3(p3x,p3y);
        int ans = (intersection(p0,p1,p2,p3))? 1 : 0;
        printf("%d\n",ans);
        
    }
    return 0;
}
