#include<iostream>
using namespace std;

int main()
{
    double x0, y0, x1, y1, x2, y2, x3, y3;
    int q;

    cin >> q;

    //内積
    for( int i = 0; i < q; i++ )
    {
        cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

        double a, b, c, d, x, y;
        a = x1 - x0;
        b = y1 - y0;
        c = x3 - x2;
        d = y3 - y2;

        double sx1, lx1; 
        if( x0 < x1 )
        {
            sx1 = x0;
            lx1 = x1;
        }
        else
        {
            sx1 = x1;
            lx1 = x0;
        }

        double sx2, lx2;
        if( x2 < x3 )
        {
            sx2 = x2;
            lx2 = x3;
        }
        else
        {
            sx2 = x3;
            lx2 = x2;
        }

        double sy1, ly1;
        if( y0 < y1 )
        {
            sy1 = y0;
            ly1 = y1;
        }
        else
        {
            sy1 = y1;
            ly1 = y0;
        }

        double sy2, ly2;
        if( y2 < y3 )
        {
            sy2 = y2;
            ly2 = y3;
        }
        else
        {
            sy2 = y3;
            ly2 = y2;
        }

        if( a == 0 )
        {
            if( c == 0 )
            {
                if( x0 != x2 || x0 == x2 && ly2 < sy1 || x0 == x2 && ly1 < sy2 )
                    cout << 0 << endl;
                else
                    cout << 1 << endl;
            }
            else if( d == 0 && sy1 <= y2 && y2 <= ly1 && sx2 <= x0 && x0 <= lx2 )
                cout << 1 << endl;
            else if( d == 0 )
                cout << 0 << endl;
            else
            {
                x = x0;
                y = d * x0 / c + y2 - d * x2 / c;
                if( sx2 <= x && x <= lx2 && sy1 <= y && y <= ly1 )
                    cout << 1 << endl;
                else
                    cout << 0 << endl;
            }
        }
        else if( b == 0 )
        {
            if( c == 0 && sx1 <= x2 && x2 <= lx1 && sy2 <= y0 && y0 <= ly2 )
                cout << 1 << endl;
            else if( c == 0 )
                cout << 0 << endl;
            else if( d == 0 )
            {
                if( y0 != y2 )
                    cout << 0 << endl;
                else
                    if( sx1 <= sx2 && sx2 <= lx1 || sx2 <= sx1 && sx1 <= lx2 )
                        cout << 1 << endl;
                    else
                        cout << 0 << endl;
            }
            else
            {
                x = ( y0 - y2 + d * x2 / c ) / ( d / c );
                y = y0;
                if( sx1 <= x && x <= lx1 && sy2 <= y && y <= ly2 )
                    cout << 1 << endl;
                else
                    cout << 0 << endl;
            }
        }
        else if( c == 0 )
        {
            x = x2;
            y = b * x / a + y0 - b * x0 / a;
            if( sx1 <= x && x <= lx1 && sy2 <= y && y <= ly2 )
                cout << 1 << endl;
            else
                cout << 0 << endl;
        }
        else if( d == 0 )
        {
            x = ( y2 - y0 + b * x0 / a ) / ( b / a );
            y = y2;
            if( sx2 <= x && x <= lx2 && sy1 <= y && y <= ly1 )
                cout << 1 << endl;
            else
                cout << 0 << endl;
        }
        else
        {
            if( b / a == d / c )
            {
                if( y0 - b * x0 / a != y2 - d * x2 / c )
                    cout << 0 << endl;
                else
                {
                    if( sx1 <= sx2 && sx2 <= lx1 || sx1 <= lx2 && lx2 <= lx1 )
                        cout << 1 << endl;
                    else if( sx2 <= sx1 && sx1 <= lx2 )
                        cout << 1 << endl;
                    else
                        cout << 0 << endl;
                }
            }
            else
            {
                x = - ( y0 - y2 + d * x2 / c - b * x0 / a ) / ( b / a - d / c );
                y = b * x / a + y0 - b * x0 / a;
                if( sx1 <= x && x <= lx1 && sy2 <= y && y <= ly2 )
                    cout << 1 << endl;
                else
                    cout << 0 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3232