import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

bool isOnSegment(Vec2 p, Vec2 a, Vec2 b) {
    auto ab = b - a;
    auto ap = p - a;

    if (ab.cross(ap) != 0)
        return false;

    // ab ??¨ ap ????????????
    if (ab.dot(ap) < 0)
        return false;

    // p ??? ab ?????????????????????
    if (ab.magSq() >= ap.magSq())
        return true;

    return false;
}

bool isIntersectLineSegments(Vec2 a, Vec2 b, Vec2 c, Vec2 d) {
    auto s = (b - a).cross(c - a) * (b - a).cross(d - a);
    auto t = (d - c).cross(a - c) * (d - c).cross(b - c);

    if (s < 0 && t < 0)
        return true;

    // ???????????????????????????
    if (isOnSegment(c, a, b) || isOnSegment(d, a, b) || isOnSegment(a, c, d) || isOnSegment(b, c, d)) {
        return true;
    }
    return false;
}

void main() {
    int q = readint();
    for (int i = 0; i < q; i++) {
        auto xs = readints();
        auto a = Vec2(xs[0], xs[1]);
        auto b = Vec2(xs[2], xs[3]);
        auto c = Vec2(xs[4], xs[5]);
        auto d = Vec2(xs[6], xs[7]);

        if (isIntersectLineSegments(a, b, c, d))
            writeln(1);
        else
            writeln(0);
    }
}

struct Vec2 {
    immutable double x;
    immutable double y;

    this(double x, double y) {
        this.x = x;
        this.y = y;
    }

    Vec2 opAdd(Vec2 other) {
        return Vec2(this.x + other.x, this.y + other.y);
    }

    Vec2 opSub(Vec2 other) {
        return Vec2(this.x - other.x, this.y - other.y);
    }

    Vec2 opMul(double d) {
        return Vec2(this.x * d, this.y * d);
    }

    double dot(Vec2 other) {
        return this.x * other.x + this.y * other.y;
    }

    double cross(Vec2 other) {
        return this.x * other.y - other.x * this.y;
    }

    double mag() {
        return sqrt(magSq());
    }

    double magSq() {
        return this.x * this.x + this.y * this.y;
    }

    Vec2 normalize() {
        auto m = mag();
        if (m != 0 && m != 1)
            return Vec2(this.x / m, this.y / m);
        return this;
    }

    static double distance(Vec2 a, Vec2 b) {
        return (a - b).mag();
    }
}