#include <iostream>
#include <string.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <set>
#include <stdio.h>
#include <time.h>
#include<complex>
#include <vector>
using namespace std;
typedef long long ll;
#define lowBit(x) ((x)&(-x))
#define rep(i,a,n) for (ll i=a;i<=n;i++)
#define per(i,a,n) for (ll i=n;i>=a;i--)
#define pb push_back
#define SZ(x) ((ll)(x).size())
typedef vector<ll> VI;
const ll N=1e6+5;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll readn(){ll sum=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){sum=sum*10+(ch-'0');
ch=getchar();}return sum*f;}


const double epx=1e-7; 
typedef complex<double> kk;
int op(kk a,kk b,kk c)
{
    b-=a,c-=a,a=c*conj(b);
    if(a.imag()>epx) return 1;
    if(a.imag()<-epx) return -1;
    if(a.real()<-epx) return 2;
    if(abs(b)+epx<abs(c)) return -2;
    return 0;
}
bool xiangjiao(kk a,kk b,kk c,kk d)
{return (op(a,b,c)*op(a,b,d)<=0)&&(op(c,d,a)*op(c,d,b)<=0);}

int main()
{
    int _;_=readn();
    while(_--)
    {
        double x1,x2,x3,x4,y1,y2,y3,y4;
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
        printf("%d\n",xiangjiao(kk(x1,y1),kk(x2,y2),kk(x3,y3),kk(x4,y4)));
    }
}
