/*
TASK:mov
LANG:C++
*/
#include <iostream>

using namespace std;

int n;
int st=-1;
long int xa,ya,xb,yb,xc,yc,xd,yd,x,y;
char result[1000];
double xz;

/*
3
1 0 0 1 0 0 -1 -1 1 1 
1 0 0 1 0 0 1 1 1 1 
1 0 0 1 3 3 4 4 1 1 
*/
int cxz()
{
    if((xa>=xb)&&(xc>=xd)) if((xz>=xb)&&(xz<=xa)&&(xz>=xd)&&(xz<=xc)) {return 1;}
    if((xa>=xb)&&(xc>=xb)) if((xz>=xb)&&(xz<=xa)&&(xz<=xd)&&(xz>=xc)) {return 1;}
    if((xb>=xa)&&(xc>=xd)) if((xz<=xb)&&(xz>=xa)&&(xz>=xd)&&(xz<=xc)) {return 1;}
    if((xb>=xa)&&(xd>=xc)) if((xz<=xb)&&(xz>=xa)&&(xz<=xd)&&(xz>=xc)) {return 1;}
    return 0;
}

int cross()
{
    double a1,a2=(yc-yd)/(xc-xd),b1,b2=yc-a2*xc;
    a1=(ya-yb)/(xa-xb);
    b1=ya-a1*xa;
    xz=(b2-b1)/(a1-a2);
    if(cxz()==1) return 1;
    return 0;
}

char checkk()
{
    long int i;
    char ch='0';
    while((xa>-1000000)&&(xa<1000000))
    {
        if (cross()==1)
        {
            ch='1';
            break;
        }
        xa+=x;
        ya+=y;
        xb+=x;
        yb+=y;
    }
    return ch;
}

int input()
{
    int i;
    cin>>n;
    for(i=0;i<n;i++) 
    {
        cin>>xa>>ya>>xb>>yb>>xc>>yc>>xd>>yd>>x>>y;
        result[i]=checkk();
    }
    return 0;
}

int main()
{
    input();
    cout<<result;
    cout<<"\n";
    system("pause");
    return 0;
}
