#include<stdio.h>
int ifcl(int p0[2],int p1[2],int p2[2],int p3[2]){
  int x0=p1[0]-p0[0],x1=p2[0]-p0[0],x2=p3[0]-p0[0],x3=x2-x1,x4=x0-x1,x5=-x1;
  int y0=p1[1]-p0[1],y1=p2[1]-p0[1],y2=p3[1]-p0[1],y3=y2-y1,y4=y0-y1,y5=-y1;
  return (x0*y1-y0*x1)*(x0*y2-y0*x2)<=0&&(x3*y4-y3*x4)*(x3*y5-y3*x5)<=0?1:0;
}
int main(){
  int p[4][2],n,i;
  scanf("%d",&n);
  while(n--){
    for(i=0;i<8;i++)scanf("%d",&p[i/2][i%2]);
    printf("%d\n",ifcl(p[0],p[1],p[2],p[3]));
  }
  return 0;
}