#include <iostream>
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <tuple>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

double eps = 1e-8;

struct point /* vec */ {
    double x, y;
    point operator+(const point &p) {
        return {x + p.x, y + p.y};
    }
    point operator-(const point &p) {
        return {x - p.x, y - p.y};
    }
};

struct line {
    // ax + by + c = 0
    double a, b, c;
};

struct circle {
    point p;
    double r;
};

double dot(point P, point Q) {
    return P.x*Q.x + P.y*Q.y;
}

double cross_2d(point P, point Q) {
    return P.x*Q.y - P.y*Q.x;
}

double points_distance(point A, point B, int deg) {
    point C = B - A;
    return pow(C.x*C.x + C.y*C.y, 0.5 * deg);
}

line line_2points(point P, point Q) {
    return {P.y - Q.y, Q.x - P.x, P.x*Q.y - P.y*Q.x};
}

point lines_intersection(line l, line m) {
    if (abs(l.a*m.b - l.b*m.a) < eps) {
        assert(-1);
    }
    return {- (l.b*m.c - l.c*m.b) / (l.b*m.a - l.a*m.b),
            - (l.a*m.c - l.c*m.a) / (l.a*m.b - l.b*m.a)};
}

bool line_same(line l, line m) {
    if (l.c * m.c == 0) {
        if (l.c == m.c) {
            if (l.b * m.b == 0) {
                if (l.b == m.b) return 1;
                else return 0;
            }
            else return l.a / l.b == m.a / m.b; 
        }
        else return 0;
    }
    else return l.a / l.c == m.a / m.c && l.b / l.c == m.b / m.c;
}

bool on_line(point P, point Q, point R) {
    if (P.x > Q.x) swap(P, Q);
    if (P.y > Q.y) swap(P.y, Q.y);
    return (P.x <= R.x && R.x <= Q.x && P.y <= R.y && R.y <= Q.y);
}

double point_line_distance(point P, line l) {
    return abs(l.a * P.x + l.b * P.y + l.c) / sqrt(l.a*l.a + l.b*l.b);
}

double is_segments_intersect(point p1, point p2, point q1, point q2) {
    line s0 = line_2points(p1, p2);
    line s1 = line_2points(q1, q2);
    if (abs(s0.a*s1.b - s0.b*s1.a) < eps) {
        if (p1.x > p2.x) swap(p1, p2);
        if (p1.y > p2.y) swap(p1.y, p2.y);
        if (q1.x > q2.x) swap(q1, q2);
        if (q1.y > q2.y) swap(q1.y, q2.y);
        if (line_same(s0, s1)) {
            return (q1.x <= p2.x && p1.x <= q2.x && q1.y <= p2.y && p1.y <= q2.y);
        }
        else return 0;
    }
    return cross_2d(p2 - p1, q1 - p1) * cross_2d(p2 - p1, q2 - p1) < eps
        && cross_2d(q2 - q1, p1 - q1) * cross_2d(q2 - q1, p2 - q1) < eps;
}

vector<point> circles_intersection(circle A, circle B) {
    vector<point> ret;
    point X = A.p;
    B.p = B.p - A.p;
    A.p = {0, 0};

    if (points_distance(A.p, B.p, 2) - pow(A.r + B.r, 2) > eps) return ret;

    double K = (B.p.x*B.p.x + B.p.y*B.p.y + A.r*A.r - B.r*B.r) / 2;
    double SQ = (B.p.x*B.p.x + B.p.y*B.p.y)*A.r*A.r - K * K;
    double DS = points_distance(A.p, B.p, 2);
    //cerr << K _ SQ _ DS << endl;
    if (abs(SQ) < eps) {
        ret.push_back({K*B.p.x / DS + X.x, K*B.p.y / DS + X.y});
        return ret;
    }
    ret.push_back({(K*B.p.x + B.p.y*sqrt(SQ)) / DS + X.x,
                   (K*B.p.y - B.p.x*sqrt(SQ)) / DS + X.y});
    ret.push_back({(K*B.p.x - B.p.y*sqrt(SQ)) / DS + X.x,
                   (K*B.p.y + B.p.x*sqrt(SQ)) / DS + X.y});
    return ret;
}
 
int main() {
    //cout << fixed << setprecision(10);
    int q;
    cin >> q;
    while (q--) {
        point p[4];
        for (int i = 0; i < 4; i++) {
            cin >> p[i].x >> p[i].y;
        }
        cout << is_segments_intersect(p[0], p[1], p[2], p[3]) << endl;
    }
}


Measured memory_bytes: 3296