#include <bits/stdc++.h>

#define reint register int
#define coint const int
#define codb const double

using namespace std;

codb EPS = 1e-8;

struct Vector {
    double x, y;

    inline Vector operator+(const Vector &v) const {
        return (Vector){ x + v.x, y + v.y };
    }

    inline double dot(const Vector &v) const { return x * v.x + y * v.y; }
    inline double cross(const Vector &v) const { return x * v.y - y * v.x; }
    inline double length(void) const { return sqrt(x * x + y * y); }
    inline double square(void) const { return x * x + y * y; }
    inline double getAngle(void) const { return atan2(y, x); }

    inline Vector operator*(const double a) const {
        return (Vector){ x * a, y * a };
    }
};

struct Point {
    double x, y;

    inline Vector operator-(const Point &p) const {
        return (Vector){ x - p.x, y - p.y };
    }

    inline Point operator+(const Vector &v) const {
        return (Point){ x + v.x, y + v.y };
    }
};

struct Segment {
    Point s, t;

    inline int isIntersectWith(const Segment &seg) const {
        codb minX1 = min(s.x, t.x), maxX1 = max(s.x, t.x);
        codb minY1 = min(s.y, t.y), maxY1 = max(s.y, t.y);
        codb minX2 = min(seg.s.x, seg.t.x), maxX2 = max(seg.s.x, seg.t.x);
        codb minY2 = min(seg.s.y, seg.t.y), maxY2 = max(seg.s.y, seg.t.y);
        if (minX1 - EPS > maxX2 || maxX1 + EPS < minX2
            || minY1 - EPS > maxY2 || maxY1 + EPS < minY2)
            return 0;
        const Vector vec1 = t - s, vec2 = seg.t - seg.s;
        codb prof1 = (s - seg.s).cross(vec2) * vec2.cross(t - seg.s);
        codb prof2 = (seg.s - s).cross(vec1) * vec1.cross(seg.t - s);
        if (prof1 + EPS > 0 && prof2 + EPS > 0)
            return 1;
        else return 0;
    }
};

inline int isEq(const double a, const double b) {
    return abs(a - b) < EPS;
}

int main(void) {
    int q;
    scanf("%d", &q);
    while (q--) {
        Point p0, p1, p2, p3;
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",
              &p0.x, &p0.y, &p1.x, &p1.y, &p2.x, &p2.y, &p3.x, &p3.y);
        const Segment seg1 = (Segment){ p0, p1 }, seg2 = (Segment){ p2, p3 };
        printf("%d\n", seg1.isIntersectWith(seg2));
    }

    return 0;
}

