#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>

int dcmp(double x) {
    static double eps = 1e-8;
    return (x > eps) - (x < -eps);
}

struct vec{
    double x, y;

    vec(double _x=0, double _y=0)
        :x(_x), y(_y) {}

    vec operator- () const{ return vec(-x, -y); }
    
    vec operator+ (const vec& v) const{ return vec(x+v.x, y+v.y); }
    vec operator- (const vec& v) const{ return vec(x-v.x, y-v.y); }
    vec operator* (double c) const{ return vec(x*c, y*c); }
    vec operator/ (double c) const{ return vec(x/c, y/c); }

    double dot(const vec& v) const{ return x*v.x + y*v.y; }
    double cross(const vec& v) const{ return x*v.y - y*v.x; }

    double len2() const{ return x*x + y*y; }
    double len() const{ return sqrt(len2()); }
    
    vec& norm() { return *this = *this / len(); }
    vec& rot(double rad) {
        return  *this = vec(x*cos(rad) - y*sin(rad), x*sin(rad) + y*cos(rad));
    }

    bool operator< (const vec& v) const{
        return dcmp(x-v.x) < 0 || (dcmp(x-v.x)==0 && dcmp(y-v.y) < 0);
    }
    bool operator== (const vec& v) const{
        return dcmp(x-v.x) == 0 && dcmp(y-v.y) == 0;
    }
};

struct line{
    vec u, v; // u + x*v

    line() {}
    line(vec _u, vec _v)
        :u(_u), v(_v) {}

    vec get(double x) const{ return u + v * x; }
    
    bool on_left(vec p) const{ return dcmp(v.cross(p - u)) > 0; }
    
    vec proj(vec p) const{ return get(v.dot(p - u)); }
    vec refl(vec p) const{ return p + (proj(p) - p) * 2; }
    
    vec line_intersection(line b) const{
        return b.u + b.v * b.v.cross(b.u-u) / v.cross(b.v);
    }
};

line makeline(vec a, vec b) {
    return line(a, (b - a).norm());
}

bool in_segment(vec a, vec b, vec c) {
    vec u = a - c, v = b - c;
    return a == c || b == c || (dcmp(u.cross(v)) == 0 && dcmp(u.dot(v)) < 0);
}

bool segment_intersection(vec a, vec b, vec c, vec d) {
    line x = line(a, b-a), y = line(c, d-c);
    return in_segment(a, b, c) || in_segment(a, b, d) ||
           in_segment(c, d, a) || in_segment(c, d, b) ||
           (x.on_left(c) != x.on_left(d) && y.on_left(a) != y.on_left(b));
}

bool is_convex(const std::vector<vec>& p) {
    for (size_t i = 0, j = 1, k; j < p.size(); i++, j++) {
        k = (j + 1) % p.size();
        if ((p[j] - p[i]).cross(p[k] - p[j]) < 0)
            return false;
    }
    return true;
}

std::vector<vec> convex_hull(std::vector<vec> p) {
    std::sort(p.begin(), p.end());
    std::vector<vec> ch;
    for (size_t i = 0; i < p.size(); ++i) {
        while (ch.size() > 1 && makeline(ch[ch.size()-2], p[i]).on_left(ch[ch.size()-1]))
            ch.pop_back();
        ch.push_back(p[i]);
    }
    size_t k = ch.size();
    for (int i = p.size() - 2; i >= 0; --i) {
        while (ch.size() > k && makeline(ch[ch.size()-2], p[i]).on_left(ch[ch.size()-1]))
            ch.pop_back();
        ch.push_back(p[i]);
    }
    ch.pop_back();
    return ch;
}

std::pair<vec, vec> convex_diameter(const std::vector<vec> &p) {
    int xmax = 0, xmin = 0, n = p.size();
    for (int i = 1; i < n; ++i) {
        if (p[i].x > p[xmax].x) xmax = i;
        if (p[i].x < p[xmin].x) xmin = i;
    }
    
    int i = xmax, j = xmin;
    int u = xmax, v = xmin;
    double ans = (p[xmax] - p[xmin]).len2();
    
    do {
        if ((p[i] - p[(i + 1) % n]).cross(p[j] - p[(j + 1) % n]) < 0) i = (i + 1) % n;
        else j = (j + 1) % n;

        double dist = (p[i] - p[j]).len2();
        if (dist > ans) {
            ans = dist;
            u = i; v = j;
        }
    }while(i != xmax || j != xmin);
    return std::make_pair(p[u], p[v]);
}

double polygon_area(const std::vector<vec>& v) {
    double area = 0;
    for (size_t i = 0; i < v.size(); ++i)
        area += v[i].cross(v[(i + 1) % v.size()]);
    return area * 0.5;
}

int relation(const std::vector<vec>& p, const vec& v) {
    int ret = -1, n = p.size();
    for (int i = 0; i < n; ++i) {
        vec a = p[i] - v, b = p[(i + 1) % n] - v;
        if (a.y > b.y) std::swap(a, b);
        if (a.y <= 0 && 0 < b.y && a.cross(b) < 0)
            ret = -ret;
        if (a.cross(b) == 0 && a.dot(b) <= 0) return 0;
    }
    
    return ret; // 1 - contain, -1 - out
}

// end template

int main() {
    int q;
    scanf("%d", &q);
    while (q--) {
        vec a, b, c, d;
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",
              &a.x, &a.y, &b.x, &b.y, &c.x, &c.y, &d.x, &d.y);

        puts(segment_intersection(a, b, c, d) ? "1": "0");
    }
    return 0;
}



Measured memory_bytes: 2772