#include <stdio.h>

void closs(double a1[2], double b1[2],
            double a2[2], double b2[2],double ans[2]);

int main(void)
{
    double a1[2], b1[2], a2[2], b2[2], ans[2];
    int n, i;
    double maxx1, minx1, maxx2, minx2, maxy1, miny1, maxy2, miny2;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%lf%lf%lf%lf", &a1[0], &a1[1], &b1[0], &b1[1]);
        scanf("%lf%lf%lf%lf", &a2[0], &a2[1], &b2[0], &b2[1]);

        closs(a1, b1, a2, b2, ans);

        //printf("%lf\n%lf\n", ans[0], ans[1]);

        maxx1 = (a1[0] < b1[0]) ? b1[0] : a1[0];
        minx1 = (a1[0] >= b1[0]) ? b1[0] : a1[0];
        maxx2 = (a2[0] < b2[0]) ? b2[0] : a2[0];
        minx2 = (a2[0] >= b2[0]) ? b2[0] : a2[0];
        maxy1 = (a1[1] < b1[1]) ? b1[1] : a1[1];
        miny1 = (a1[1] >= b1[1]) ? b1[1] : a1[1];
        maxy2 = (a2[1] < b2[1]) ? b2[1] : a2[1];
        miny2 = (a2[1] >= b2[1]) ? b2[1] : a2[1];

        if (minx1 <= ans[0] && ans[0] <= maxx1
                && minx2 <= ans[0] && ans[0] <= maxx2
                && miny1 <= ans[1] && ans[1] <= maxy1
                && miny2 <= ans[1] && ans[1] <= maxy2 ) {
            puts("1");
        } else {
            puts("0");
        }
    }
    return 0;
}

void closs(double a1[2], double b1[2],
            double a2[2], double b2[2],double ans[2]) 
{
    double s1, s2;

    s1 = ((b2[0] - a2[0])*(a1[1] - a2[1]) 
            - ((b2[1] - a2[1])*(a1[0] - a2[0]))) / 2;

    s2 = ((b2[0] - a2[0])*(a2[1] - b1[1]) 
            - ((b2[1] - a2[1])*(a2[0] - b1[0]))) / 2;

    ans[0] = a1[0] + (b1[0] - a1[0])*s1/(s1 + s2);
    ans[1] = a1[1] + (b1[1] - a1[1])*s1/(s1 + s2);
}