#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

const double EPS = 1e-10;
bool eq(double a, double b) {return fabs(a - b) < EPS;}

struct Point {
    double x, y;
    Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}
    Point operator + (Point &p);
    Point operator - (Point &p);
    Point operator * (double k);
    Point operator / (double k);
    bool operator == (const Point &p) const;
    double norm();
    double abs();
    void print();
} typedef Vec;

struct Segment {
    Point p1, p2;
    Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
    Segment(double x1, double y1, double x2, double y2) : p1(Point(x1, y1)), p2(Point(x2, y2)) {}
} typedef Line;

struct Circle {
    Point o; double r;
    Circle(Point o, double r) : o(o), r(r) {}
    Circle(double x, double y, double r) : o(Point(x, y)), r(r) {}
};

double norm(Vec a);
double abs(Vec a);

double dot(Vec a, Vec b);
double cross(Vec a, Vec b);

int ccw(Point a, Point b, Point c);
bool intersect(Point a1, Point a2, Point b1, Point b2);
bool intersect(Segment s1, Segment s2);

bool isOrthogonal(Vec a, Vec b);
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2);
bool isOrthogonal(Segment s1, Segment s2);

bool isParallel(Vec a, Vec b);
bool isParallel(Point a1, Point a2, Point b1, Point b2);
bool isParallel(Segment s1, Segment s2);

Point project(Segment s, Point p);
Point reflect(Segment s, Point p);

int main() {
    int q; cin >> q;
    while(q--) {
        double x, y, x2, y2;
        cin >> x >> y >> x2 >> y2;
        Line s(x, y, x2, y2);
        cin >> x >> y >> x2 >> y2;
        Line s2(x, y, x2, y2);
        cout << intersect(s, s2) << '\n';
    }
    return 0;
}

Point Point::operator + (Point &p) {return Point(x + p.x, y + p.y);}
Point Point::operator - (Point &p) {return Point(x - p.x, y - p.y);}
Point Point::operator * (double k) {return Point(x * k, y * k);}
Point Point::operator / (double k) {return Point(x / k, y / k);}
bool Point::operator == (const Point &p) const {return eq(x, p.x) && eq(y, p.y);}
double Point::norm() {return x * x + y * y;}
double Point::abs() {return sqrt(norm());}
void Point::print() {printf("%.10lf %.10lf\n", x, y);}

double norm(Vec a) {return a.x * a.x + a.y * a.y;}
double abs(Vec a) {return sqrt(norm(a));}

double dot(Vec a, Vec b) {return a.x * b.x + a.y * b.y;}
double cross(Vec a, Vec b) {return a.x * b.y - a.y * b.x;}

int ccw(Point a, Point b, Point c) {
    b = b - a;
    c = c - a;
    if(cross(b, c) > EPS) return 1; // COUNTER_CLOCKWISE
    if(cross(b, c) < -EPS) return -1; // CLOCKWISE
    if(dot(b, c) < -EPS) return 2; // ONLINE_BACK
    if(norm(b) < norm(c)) return -2; // ONLINE_FRONT
    return 0; // ON_SEGMENT
}
bool intersect(Point a1, Point a2, Point b1, Point b2) {
    return (ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0 &&
            ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0);
}
bool intersect(Segment s1, Segment s2) {return intersect(s1.p1, s1.p2, s2.p1, s2.p2);}

bool isOrthogonal(Vec a, Vec b) {return eq(dot(a, b), 0.0);}
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {return isOrthogonal(a1 - a2, b1 - b2);}
bool isOrthogonal(Segment s1, Segment s2) {return eq(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);}

bool isParallel(Vec a, Vec b) {return eq(cross(a, b), 0.0);}
bool isParallel(Point a1, Point a2, Point b1, Point b2) {return isParallel(a1 - a2, b1 - b2);}
bool isParallel(Segment s1, Segment s2) {return eq(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);}

Point project(Segment s, Point p) {
    Vec base = s.p2 - s.p1;
    double r = dot(p - s.p1, base) / norm(base);
    return base * r + s.p1;
};
Point reflect(Segment s, Point p) {return (project(s, p) - p) * 2.0 + p;}



Measured memory_bytes: 3232