#include <stdio.h>
#include <math.h>

int cross(double x0,double y0,double x1,double y1,double x2,double y2,double x3,double y3){
  double a0=0,a1=0,b0=0,b1=0;
  double tx=0,ty=0,p0p1=0,p2p3=0,len1=0,len2=0;
  
  a0=(y1-y0)/(x1-x0);
  a1=(y3-y2)/(x3-x2);
  b0=y0-a0*x0;
  b1=y2-a1*x2;
  //???????±???????
  tx=(b0-b1)/(a1-a0);
  ty=a0*tx+b0;
  p0p1=sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
  p2p3=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
  len1=sqrt((tx-x0)*(tx-x0)+(ty-y0)*(ty-y0));
  len2=sqrt((tx-x2)*(tx-x2)+(ty-y2)*(ty-y2));
  if(p0p1<len1 || p2p3<len2 || (y2-y0)==(y3-y1)) return 0;
  else return 1;
  
}




int main(){
   int number,i,m;
  double x0,y0,x1,y1,x2,y2,x3,y3;
  scanf("%d",&number);
  for(i=0;i<number;i++){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x0,&y0,&x1,&y1,&x2,&y2,&x3,&y3);
    m=cross(x0,y0,x1,y1,x2,y2,x3,y3);
    
    printf("%d\n",m);
    
  }
  return 0;
}