#include<stdio.h>
#include<stdlib.h>

struct point {
        double x;
        double y;
};
int ccw(struct point, struct point, struct point, struct point);
main()
{
        int i, n;
        struct point p[4];
        scanf("%d", &n);
        for (i = 0; i < n; i++) {
                scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &p[0].x, &p[0].y
                                  , &p[1].x, &p[1].y, &p[2].x, &p[2].y, &p[3].x, &p[3].y);
                if (ccw(p[0], p[1], p[2], p[3])<=0 && ccw(p[2], p[3], p[0], p[1])<=0) {
                        printf("1\n");
                } else {
                        printf("0\n");
                }
        }
}
int ccw(struct point p0, struct point p1, struct point p2, struct point p3)
{
        int ans;
        struct point v[3];
        v[0].x = p1.x - p0.x; v[0].y = p1.y - p0.y;
        v[1].x = p2.x - p0.x; v[1].y = p2.y - p0.y;
        v[2].x = p3.x - p0.x; v[2].y = p3.y - p0.y;
        ans = (v[0].x * v[1].y - v[0].y * v[1].x)
                * (v[0].x * v[2].y - v[0].y * v[2].x);
        if (!ans) {
                if ((v[0].x * v[1].x - v[0].y * v[1].y) < 0
                        && (v[0].x * v[2].x - v[0].y * v[2].y) < 0) {
                        return 1;
                } else if ((v[0].x * v[1].x - v[0].y * v[1].y) > 0
            && (v[0].x * v[2].x - v[0].y * v[2].y) > 0){
                        return 0;
                } else {
                        return -1;
                }
        }
        return ans;
}
