#include <bits/stdc++.h>
using namespace std;
constexpr double EPS = 1e-14;

struct vec2 {
    double x, y;
    vec2 operator+(const vec2 rhs) {
        return {x + rhs.x, y + rhs.y};
    }
    vec2 operator-(const vec2 rhs) {
        return {x - rhs.x, y - rhs.y};
    }
    vec2 operator*(const double k) {
        return {x * k, y * k};
    }
    vec2 operator/(const double k) {
        return {x / k, y / k};
    }
};

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

double norm2(vec2 a) {
    return dot(a, a);
}

struct line {
    vec2 p, l;
};

line make_line(vec2 a, vec2 b) {
    return {a, b - a};
}

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

bool is_parallel(vec2 a, vec2 b) {
    return abs(cross(a, b)) < EPS;
}

bool is_parallel(line a, line b) {
    return is_parallel(a.l, b.l);
}

double operator/(vec2 a, vec2 b) {
    assert(is_parallel(a, b));
    return a.x / b.x;
}

void printvec2(vec2 p, int precision) {
    cout << setprecision(precision) << fixed << p.x << " " << p.y << endl;
}

vec2 intersection(line l1, line l2) {
    assert(!is_parallel(l1, l2));
    double a = l1.p.x, b = l1.p.y, c = l1.l.x, d = l1.l.y;
    double e = l2.p.x, f = l2.p.y, g = l2.l.x, h = l2.l.y;
    double k = (h * (a - e) - g * (b - f)) / (g * d - c * h);
    return {
        a + k * c,
        b + k * d
    };
}

vec2 get_normal(vec2 p) {
    return {-p.y, p.x};
}

vec2 foot(vec2 p, line l) {
    line normal = {p, get_normal(l.l)};
    return intersection(normal, l);
}

vec2 reflect(vec2 p, line l) {
    vec2 f = foot(p, l);
    return {2 * f.x - p.x, 2 * f.y - p.y};
}

double dist2(vec2 p, line l) {
    return norm2(foot(p, l) - p);
}

double dist2(vec2 p, vec2 q) {
    return norm2(q - p);
}

int sgn(double a) {
    if (a < -EPS) return -1;
    if (a > EPS) return 1;
    return 0;
}

struct segment {
    vec2 a, b;
};

segment make_segment(vec2 a, vec2 b) {
    return {a, b};
}

double dist2(vec2 p, segment s) {
    vec2 l = s.a, r = s.b;
    for (int i = 0; i < 100; i++) {
        vec2 ml = (l + r) / 3;
        vec2 mr = (l + r) * 2 / 3;
        if (dist2(p, ml) > dist2(p, mr)) {
            l = ml;
        } else {
            r = mr;
        }
    }
    return dist2(p, l);
}

template<class T>
struct ext {
    double val;
    T x, y;
};

template<class T>
ext<T> ternary_2d(function<double(T, T)> f, T xl, T xr, T yl, T yr, bool maximum = true) {
    if (!maximum) {
        function<double(T, T)> g = [&](T a, T b){return -f(a, b);};
        ext<T> ret = ternary_2d(g, xl, xr, yl, yr, true);
        return {-ret.val, ret.x, ret.y};
    }
    // fix y
    function<ext<T>(T, T, T)> fx = [&](T y, T l, T r) {
        for (int i = 0; i < 100; i++) {
            T ml = (l * 2 + r) / 3.0;
            T mr = (l + r * 2) / 3.0;
            if (f(ml, y) < f(mr, y)) {
                l = ml;
            } else {
                r = mr;
            }
        }
        ext<T> ret;
        ret.x = l;
        ret.y = y;
        ret.val = f(l, y);
        return ret;
    };

    for (int i = 0; i < 100; i++) {
        T ml = (yl * 2 + yr) / 3.0;
        T mr = (yl + yr * 2) / 3.0;
        if (f(fx(ml, xl, xr).x, ml) < f(fx(mr, xl, xr).x, mr)) {
            yl = ml;
        } else {
            yr = mr;
        }
    }
    ext<T> ret;
    ret.x = fx(yl, xl, xr).x;
    ret.y = yl;
    ret.val = f(ret.x, ret.y);
    return ret;
}

double dist2(segment s, segment t) {
    ext<vec2> ans;
    function<double(vec2, vec2)> d = [&](vec2 a, vec2 b) {
        return norm2(b - a);
    };
    ans = ternary_2d(d, s.a, s.b, t.a, t.b, false);
    return ans.val;
}

int main() {
    int q;
    cin >> q;
    while (q--) {
        double x0, y0, x1, y1, x2, y2, x3, y3;
        cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        segment a = make_segment({x0, y0}, {x1, y1}), b = make_segment({x2, y2}, {x3, y3});
        if (dist2(a, b) < EPS) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
    }
}



Measured memory_bytes: 3228