/*
TASK:mov
LANG:C++
*/
#include <iostream>
#include <cmath>
using namespace std;

long double get_func_a(long double x1, long double y1, long double x2, long double y2)
{ return (y1-y2)/(x1-x2);}

int quadrant(long double x, long double y)
{
     if(x>0)
     {
        if(y>0)return 1;
        else return 4;
     }
     else 
     {
          if(y>0) return 2;
          else return 3;
     }
}

int main()
{
    long double xa, xb, xc, xd, ya, yb, yc, yd, n, x, y;
    cin >> n;
    for(int i=1; i<=n; i++)
    {
            cin >> xa >> ya >> xb >> yb >> xc >> yc >> xd >> yd >> x >> y;
            long double max, min, temp, vect;
            temp=get_func_a(xa, ya, xd, yd);
            max=temp;
            min=max;
          //  cout << temp << endl;
            
            temp=get_func_a(xa, ya, xc, yc);
            if(temp>max)max=temp;
            if(temp<min)min=temp;
           // cout << temp << endl;
                        
            temp=get_func_a(xb, yb, xc, yc);
            if(temp>max)max=temp;
            if(temp<min)min=temp;
          //  cout << temp << endl;
            
            temp=get_func_a(xb, yb, xd, yd);
            if(temp>max)max=temp;
            if(temp<min)min=temp;
          //  cout << temp << endl;
            
            vect=y/x*x/abs(x)*y/abs(y);
            int flag=0;
            
            int quad=quadrant(x, y);
            if(quad==quadrant(xc, yc))flag=1;
            if(quad==quadrant(xd, yd))flag=1;
            
            if(vect >= min && vect <= max && flag) cout << 1;
            else cout << 0 ;
      }
      cout << endl;
      return 0;
}
            
