#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;

typedef complex<double> P;

struct L : public vector<P>{//??´???
  L(const P &a, const P &b){
    push_back(a);push_back(b);
  }
};

struct C{//???
  P c; double r;
  C(const P &c,double r): c(c),r(r){}
};

namespace std{//??????????????????
  bool operator < (const P& a,const P& b){
    return real(a)!= real(b) ? real(a) < real(b) : imag(a) < imag(b);
    //return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b)
  }
  bool operator == (const P& a,const P& b){
    return a.real()==b.real()&&a.imag()==b.imag();
  }
}

double dot(P a,P b){
  return real(conj(a)*b);
}

double cross(P a,P b){
  return imag(conj(a)*b);
}

int ccw(P a, P b, P c){
  b-=a;c-=a;
  if(cross(b,c)>0)   return +1;// counter clockwise 
  if(cross(b,c)<0)   return -1;// clockwise 
  if(dot(b,c)<0)     return +2;// c-a-b on line
  if(norm(b)<norm(c))return -2;// a-b-c on line
  return 0;                    // a-c-b on lone
}

P intersection(P a,P b,P c,P d){//2??´????????????
  return a+(b-a)*(cross(d-c,c-a)/cross(d-c,b-a));
}

int main()
{
  int i;
  int q;

  cin>>q;

  rep(i,q){
    double xp,yp;

    cin>>xp>>yp;  P p1(xp,yp);
    cin>>xp>>yp;  P p2(xp,yp);
    cin>>xp>>yp;  P p3(xp,yp);
    cin>>xp>>yp;  P p4(xp,yp);

    P s1(p2-p1);
    P s2(p4-p3);

    if(p1==p3 || p1==p4 || p2==p3 || p2==p4){
      cout<<"1"<<endl;
      continue;
    }

    if(s1.real()*s2.imag()==s1.imag()*s2.real()){//parallel
      if(ccw(p1,p3,p4)==2||ccw(p2,p3,p4)==2 || ccw(p3,p1,p2)==2||ccw(p4,p1,p2)==2)
	  cout<<"1"<<endl;
	else
	  cout<<"0"<<endl;

    }else{
      P p=intersection(p1,p2,p3,p4);//??????
      // cout<<p<<endl;
      if(abs(p1-p)>abs(p1-p2) || abs(p2-p)>abs(p1-p2) ||
	 abs(p3-p)>abs(p3-p4) || abs(p4-p)>abs(p3-p4))
	cout<<"0"<<endl;
      else
	cout<<"1"<<endl;
    }
  }

}