#include <iostream>
#include <math.h>
#include <cmath>
#include <iomanip>


using namespace std;

//-------------------------------------------------------------------------------------
/*2点[(x1,y1),(x2,y2)]を入力し二点を通る直線ax+by+cの(a,b,c)を返す,  */
/*x1==x2ならfalseを返す*/
/*falseならばx=cの形の直線*/
void straight_line_passing_through_the_two_points(double x1, double y1, double x2, double y2, double *a, double *b, double *c){
    *a=(y2-y1);
    *b=-(x2-x1);
    *c=y2*(x2-x1)-x2*(y2-y1);
}

//-------------------------------------------------------------------------------------
/*(x,y)を通るa1x+b1y+c1=0に垂直な直線a2x+b2y+c2=0を返す*/
void vertical_straight_line(double x, double y, double a1, double b1, double c1, double *a2, double *b2, double *c2){
    *a2 = -b1;
    *b2 = a1;
    *c2 = b1*x - a1*y;
}


//-------------------------------------------------------------------------------------
/*2直線 a1x+b1y+c1=0 a2x+b2y+c2=0 の交点 (x,y)を返す*/
/*2直線が平行であるならばfalseを返す*/
bool intersection_and_parallel(double a1, double b1, double c1, double a2, double b2, double c2, double *x, double *y){
    if(a1*b2==a2*b1)return false;//平行の判定
    
    *x = (b1*c2-b2*c1)/(a1*b2-a2*b1);
    *y = (a2*c1-a1*c2)/(a1*b2-a2*b1);
    
    return true;
}

//-------------------------------------------------------------------------------------
/* 
 a1x+b1y+c1=0 と　a2x+b2y+c2=0 が
 平行なら2
 直交なら1
 それ以外は0
 を返す
 */
int judges_whether_parallel_or_perpendicular(double a1, double b1, double c1, double a2, double b2, double c2){
    if(a1*b2 == a2*b1)return 2;
    if(a1*a2 + b1*b2 == 0)return 1;
    return 0;
}


//-------------------------------------------------------------------------------------
/*直線ax+by+c=0に対し　(x1,y1)と線対称な位置(x2,y2)を出力*/
/*vertical_straight_lineを使用*/
/*intersection_and_parallelを使用*/
void line_symmetry(double a, double b, double c, double x1, double y1, double *x2, double *y2){
    //垂直な直線を求める
    double a2,b2,c2;
    vertical_straight_line(x1, y1, a, b, c, &a2, &b2, &c2);
    
    //垂直な直線との交点を求める
    double c_x, c_y;
    intersection_and_parallel(a, b, c, a2, b2, c2, &c_x, &c_y);
    *x2 = x1 + 2*(c_x-x1);
    *y2 = y1 + 2*(c_y-y1);
}



//-------------------------------------------------------------------------------------
/*2点(x1,y1), (x2,y2) の距離*/
double distance_between_the_two_pointss(double x1,double y1, double x2, double y2){
    return  sqrt(fabs((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}


//-------------------------------------------------------------------------------------
/* (x1,y1)から(x2,y2)へ伸ばした直線の角度を求める  */
double angle_of_the_line(double x1, double y1, double x2, double y2){
    return atan2(y2-y1, x2-x1);
}

//-------------------------------------------------------------------------------------
/*(x1,y1)と(x2,y2)を両端に持つ線分と*/
/*(x3,y3)と(x4,y4)を両端に持つ線分が*/
/*交差するなら1 交差しないなら0を出力する*/
int line_segment_cross_decision(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4){
    double a1,b1,c1, a2,b2,c2;
    straight_line_passing_through_the_two_points(x1, y1, x2, y2, &a1, &b1, &c1);
    straight_line_passing_through_the_two_points(x3, y3, x4, y4, &a2, &b2, &c2);
    double c_x,c_y;
    bool is_parallel = intersection_and_parallel(a1, b1, c1, a2, b2, c2, &c_x, &c_y);
    if(is_parallel==false){
        if(a1*x3+b1*y3+c1==0){//一直線上にある.
            if(min(x1,x2)<=x3&&x3<=max(x1,x2)&&min(y1,y2)<=y3&&y3<=max(y1,y2))return 1;
            if(min(x1,x2)<=x4&&x4<=max(x1,x2)&&min(y1,y2)<=y4&&y4<=max(y1,y2))return 1;
            if(min(x3,x4)<=x1&&x1<=max(x3,x4)&&min(y3,y4)<=y1&&y1<=max(y3,y4))return 1;
            if(min(x3,x4)<=x2&&x2<=max(x3,x4)&&min(y3,y4)<=y2&&y2<=max(y3,y4))return 1;
            


        }
        return 0;
    }
    if(x1>x2)swap(x1, x2);
    if(x3>x4)swap(x3, x4);
    if(y1>y2)swap(y1, y2);
    if(y3>y4)swap(y3, y4);

    if(x1<=c_x&&c_x<=x2&&x3<=c_x&&c_x<=x4){
        if(y1<=c_y&&c_y<=y2&&y3<=c_y&&c_y<=y4)return 1;
    }
    return 0;
    
}

int main(int argc, const char * argv[]){
    int q;
    cin>>q;
    for(int i=0; i<q; i++){
        double x1,x2,x3,x4,y1,y2,y3,y4;
        cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
        int ans = line_segment_cross_decision(x1, y1, x2, y2, x3, y3, x4, y4);
        cout<<ans<<endl;
        
        
    }
}

Measured memory_bytes: 1232