#define loop(i, s, e) for(ll i = s;i < e;i++)

#include <iostream>
#include <iomanip>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

typedef long long signed ll;

#define NAN_M 0x800000000000
#define EPS 0.0000000001

class Position {
public:
    enum Positions {
        COUNTER_CLOCKWISE = 1,
        CLOCKWISE = -1,
        ONLINE_BACK = 2,
        ONLINE_FRONT = 3,
        ON_SEGMENT = 0
    };

    static std::string ToString(enum Positions e) {
        switch (e) {
            case COUNTER_CLOCKWISE:
                return "COUNTER_CLOCKWISE";
            case CLOCKWISE:
                return "CLOCKWISE";
            case ONLINE_BACK:
                return "ONLINE_BACK";
            case ONLINE_FRONT:
                return "ONLINE_FRONT";
            case ON_SEGMENT:
                return "ON_SEGMENT";
        }
    }
};

template<class T>
class Vector2D {
public:
    T x;
    T y;

    Vector2D() {
        x = y = 0;
    }

    Vector2D(T x_, T y_) {
        x = x_;
        y = y_;
    }

    T operator*(const Vector2D<T> *e) {
        return this->x * e->x + this->y * e->y;
    }

    Vector2D<T> operator-(const Vector2D<T> *e) {
        return Vector2D<T>(this->x - e->x, this->y - e->y);
    }

    Vector2D<T> operator+(const Vector2D<T> *e) {
        return Vector2D<T>(this->x + e->x, this->y + e->y);
    }

    T operator*(const Vector2D<T> e) {
        return this->x * e.x + this->y * e.y;
    }

    Vector2D<T> operator-(const Vector2D<T> e) {
        return Vector2D<T>(this->x - e.x, this->y - e.y);
    }

    Vector2D<T> operator+(const Vector2D<T> e) {
        return Vector2D<T>(this->x + e.x, this->y + e.y);
    }

    Vector2D<T> operator*(const T r) {
        return Vector2D<T>(this->x * r, this->y * r);
    }

    Vector2D<T> operator/(const T r) {
        return Vector2D<T>(this->x / r, this->y / r);
    }

    Vector2D<T> operator-() {
        return Vector2D<T>(-this->x, -this->y);
    }

    double abs() {
        return sqrt(x * x + y * y);
    }

    T norm() {
        return x * x + y * y;
    }

    T crossP(Vector2D<T> e) {
        if (x * e.y >= y * e.x) return (x * e.y) - (y * e.x);
        else return (y * e.x) - (x * e.y);
    }

    T cross(Vector2D<T> e) {
        return (x * e.y) - (y * e.x);
    }

    double cos(Vector2D<T> e) {
        if ((e.abs() * abs()) == 0) return NAN_M;
        return (e * (*this)) / (e.abs() * abs());
    }

    double sin(Vector2D<T> e) {
        if ((e.abs() * abs()) == 0) return NAN_M;
        return ((x * e.y) - (y * e.x)) / (e.abs() * abs());
    }
};

template<class T>
class Point2D : public Vector2D<T> {
public:
    using Vector2D<T>::Vector2D;
};

template<class T>
class Line2D {
public:
    Point2D<T> p1, p2;
    Line2D(){
        p1 = Point2D<T>(0,0);
        p2 = Point2D<T>(0,0);
    }
    Line2D(Point2D<T> p1_,Point2D<T> p2_){
        p1 = p1_;
        p2 = p2_;
    }
    Vector2D<T> getVector() {
        return p2 - p1;
    }

    Point2D<T> getProject(Point2D<T> p) {
        Vector2D<T> base = getVector();
        return p1 + base * ((p - p1) * base) / base.norm();
    }

    Point2D<T> reflect(Point2D<T> p) {
        return p + (getProject(p) - p) * 2;
    }

    virtual double getDistance(Point2D<T> p) {
        return (p2 - p1).crossP(p - p1) / (p2 - p1).abs();
    }
};

template<class T>
class Segment2D : public Line2D<T> {
public:
    using Line2D<T>::p1;
    using Line2D<T>::p2;
    using Line2D<T>::Line2D;
    double getDistance(Point2D<T> p) override{
        if ((p2 - p1).cross(p - p1) < 0) return (p - p1).abs();
        if ((p1 - p2).cross(p - p1) < 0) return (p - p1).abs();
        return Line2D<T>::getDistance(p);
    }

    Position::Positions ccw(Point2D<T> p) {
        Vector2D<T> a = p2 - p1;
        Vector2D<T> b = p - p1;
        if (a.cross(b) > EPS) return Position::Positions::COUNTER_CLOCKWISE;
        if (a.cross(b) < -EPS) return Position::Positions::CLOCKWISE;
        if (a * b < -EPS) return Position::Positions::ONLINE_BACK;
        if (a.norm() < b.norm()) return Position::Positions::ONLINE_FRONT;
        return Position::Positions::ON_SEGMENT;
    }

    bool intersect(Segment2D<T> s) {
        return ((ccw(s.p1) * ccw(s.p2) <= 0 && s.ccw(p1) * s.ccw(p2) <= 0) || ccw(s.p1) * ccw(s.p2) == 0  || s.ccw(p1) * s.ccw(p2) == 0);
    }

    double getDistance(Segment2D<T> s) {

    }
};

int main(void){
    int q;
    cin >> q;
    loop(i,0,q){
        Point2D<double> v[4];
        loop(j,0,4) {
            cin >> v[j].x >> v[j].y;
        }        int res = Segment2D<double>(v[0],v[1]).intersect(Segment2D<double>(v[2],v[3]));
        if(res) cout << 1 << endl;
        else cout << 0 << endl;
    }
}
/*
int main(void) {
    Segment2D<double> b;
    cin >> b.p1.x >> b.p1.y >> b.p2.x >> b.p2.y;
    int q;
    cin >> q;
    Point2D<double> c;
    loop(i,0,q){
        cin >> c.x >> c.y;
        cout << Position::ToString(b.ccw(c)) << endl;
    }
}*/



Measured memory_bytes: 3212