#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double inf = 1e20;
inline double sqr (double k) {return k * k;}
inline int sgn (double p) {
    if (fabs (p) < eps) return 0;
    if (p < 0) return -1;
    return 1;
}
struct point {
    double x, y;
    point (){}
    point (double _x, double _y) {
        x = _x, y = _y;
    }
    void input () {
        scanf ("%lf %lf", &x, &y);
    }
    bool operator == (point b) const {
        return sgn (x - b.x) == 0 && sgn (y - b.y) == 0;
    }
    point operator - (const point &b) const {
        return point (x - b.x, y - b.y);
    }
    double operator * (const point &b) const {
        return x * b.x + y * b.y;
    }
    double operator ^ (const point &b) const {
        return x * b.y - y * b.x;
    }
    double len () {
        return hypot (x, y);
    }
    double len2 () {
        return x * x + y * y;
    }
    double distance (point p) {
        return hypot (x - p.x, y - p.y);
    }
    point operator + (const point &b) const{
        return point (x + b.x, y + b.y);
    }
    point operator * (const double &b) const {
        return point (x * b, y * b);
    }
    point operator / (const double &b) const {
        return point (x / b, y / b);
    }
    double cross (point a, point b) {
        return (a - *this) ^ (b - *this);
    }
    double dot (point a, point b) {
        return (a - *this) * (b - *this);
    }
    bool on_seg (point a, point b) {
        return sgn (cross (a, b)) == 0 && dot (a, b) <= 0;
    }
};
bool seg (point a, point b, point c, point d) {
    if (a.on_seg (c, d) || b.on_seg (c, d) || c.on_seg (a, b) || d.on_seg (a, b)) return true;
    if (a.cross (b, d) * a.cross (b, c) < 0 && c.cross (d, b) * c.cross (d, a) < 0) return true;
    return false;
}
int main () {
//    freopen ("in.txt", "r", stdin);
    int Q;
    cin >> Q;
    while (Q --) {
        int flag1 = 0, flag2 = 0, ans;
        double u, k;
        point s1, e1, s2, e2, a, b, c;
        s1.input (), e1.input ();
        s2.input (), e2.input ();
        if (seg (s1, e1, s2, e2)) cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;
}

