#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Point
{
    ll x,y;
    Point(){ x = y = 0.0; }
    Point(ll _x, ll _y) : x(_x), y(_y){}

    Point operator+ (Point p)
    {
        return Point(p.x + x, p.y + y);
    }

    Point operator- (Point p)
    {
        return Point(x - p.x, y - p.y);
    }

    ll operator* (Point p)
    {
        return p.x * x + p.y * y;
    }

    Point operator* (ll t)
    {
        return Point(x*t, y*t);
    }

    ll operator~ ()
    {
        return x * x + y * y;
    }

    ll operator% (Point p)
    {
        return x * p.y - y * p.x;
    }

};

bool intersect(Point a, Point b, Point p, Point q)
{
    Point v1=(b-a);
    Point v2=(q-p);
    double t,t1;
    if( v1 % v2 != 0 )
    {
        t = (double)(( p - a ) % v2) / (double)(v1 % v2);
        t1 = (double)(( a - p ) % v1) / (double)(v2 % v1);
        if( t >= 0.0 && t <= 1.0 && t1 >= 0.0 && t1 <= 1.0) return true;
        else return false;
    }
    else
    {
        if( v1 % v2 == 0 && (p - a) % v1 == 0 )
        {
            t = (double)((p - a)*v1) /  (double)(v1*v1);
            t1 = (double)((p+v2-a)*v1) / (double)(v1*v1);
            if( v1 * v2 < 0 )
            {
                if( t1 <= 1.0 && 0.0 <= t ) return true;
            }
            else
            {
//                cout <<fixed << setprecision(6)<< t << " " << t1 << " " << v1*v2 << endl;
                if( t <= 1.0 && 0.0 <= t1 ) return true;
            }
        }
    }
    return false;
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    Point p0,p1,p2,p3;
    Point vec, vec1;
    int q;
    cin >> q;
    while(q--)
    {
        cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
        cout << intersect(p0,p1,p2,p3) << '\n';
    }
    return 0;
}