#include<iostream>
using namespace std;
enum POSITION{CLOCKWISE, COUNTER_CLOCKWISE, ONLINE_BACK,
              ONLINE_FRONT, ON_SEGMENT};
struct Point{
    double x;
    double y;
    Point(double x, double y) : x(x), y(y){}
    Point operator-(Point p){
        return Point(x - p.x, y - p.y);
    }
};
typedef Point Vector;
double get_cross(Vector v1, Vector v2){
    return v1.x * v2.y - v1.y * v2.x;
}
double get_dot(Vector v1, Vector v2){
    return v1.x * v2.x + v1.y * v2.y;
}
struct Segment{
    Point p1;
    Point p2;
    Segment(Point p1, Point p2) : p1(p1), p2(p2){}
};
POSITION get_position(Point p, Segment s){
    Vector base = s.p2 - s.p1;
    Vector obj  = p    - s.p1;
    double cross = get_cross(base, obj);
    if (cross >  1e-10) return CLOCKWISE;
    if (cross < -1e-10) return COUNTER_CLOCKWISE;
    if (get_dot(base, obj) < 0) return ONLINE_BACK;
    if (get_dot(base, base) < get_dot(obj, obj)) return ONLINE_FRONT;
    return ON_SEGMENT;
}
bool is_intersection(Segment s1, Segment s2){
    POSITION s2p1_s1 = get_position(s2.p1, s1);
    POSITION s2p2_s1 = get_position(s2.p2, s1);
    POSITION s1p1_s2 = get_position(s1.p1, s2);
    POSITION s1p2_s2 = get_position(s1.p2, s2);
    if (s2p1_s1 == ON_SEGMENT || s2p2_s1 == ON_SEGMENT) return true;
    if (s1p1_s2 == ON_SEGMENT || s1p2_s2 == ON_SEGMENT) return true;
    if (s2p1_s1 == ONLINE_FRONT) {
        if (s2p2_s1 == ONLINE_BACK) return true;
        return false;
    }
    if (s2p1_s1 == ONLINE_BACK) {
        if (s2p2_s1 == ONLINE_FRONT) return true;
        return false;
    }
    if (s2p1_s1 == s2p2_s1) return false;
    if (s1p1_s2 == s1p2_s2) return false;
    return true;
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3;
        cin >> x_p0 >> y_p0 >> x_p1 >> y_p1;
        cin >> x_p2 >> y_p2 >> x_p3 >> y_p3;
        Point p0(x_p0, y_p0);
        Point p1(x_p1, y_p1);
        Point p2(x_p2, y_p2);
        Point p3(x_p3, y_p3);
        Segment s1(p0, p1);
        Segment s2(p2, p3);
        int ans = 0;
        if (is_intersection(s1, s2)) ans = 1;
        cout << ans << endl;
    }
    return 0;
}

