#include <stdio.h>
#include <math.h>

#define PREC 1e-12

#define max(a, b) ((a)>(b)?(a):(b))
#define min(a, b) ((a)<(b)?(a):(b))

int main() {
    int x, y, x0, y0, x1, y1, x2, y2, x3, y3;
    int q;
    double s, t, num1, num2, denom;
    int judge;

    scanf("%d", &q);
    
    while (q--) {
        scanf("%d %d %d %d %d %d %d %d",
              &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3);
        num1 = (y3-y2)*(x2-x0)-(x3-x2)*(y2-y0);
        num2 = (y1-y0)*(x2-x0)-(x1-x0)*(y2-y0);
        denom = (x1-x0)*(y3-y2) - (y1-y0)*(x3-x2);
        if (fabs(denom) < PREC) {
            if (fabs(num1) < PREC && fabs(num2) < PREC ) {
                if ((max(x0, x1) >= min(x2, x3) && min(x0, x1) <= max(x2, x3)) &&
                    (max(y0, y1) >= min(y2, y3) && min(y0, y1) <= max(y2, y3)))
                    judge = 1;
                else
                    judge = 0;
            }
            else
                judge = 0;
        }
        else {
            s = num1 / denom;
            t = num2 / denom;
            if (s < 0 || s > 1 || t < 0 || t > 1) {
                judge = 0;
            }
            else {
                judge = 1;
            }
        }
        printf("%d\n", judge);
    }

    return 0;
}