#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

class Point {
public:
  ld x, y;

  Point() {}
  Point(ld x, ld y): x(x), y(y) {}

  Point operator + (const Point &p) {
    return Point(x + p.x, y + p.y);
  }
  Point operator - (const Point &p) {
    return Point(x - p.x, y - p.y);
  }
  Point operator * (const ld k) {
    return Point(x * k, y * k);
  }
  Point operator / (const ld k) {
    return Point(x / k, y / k);
  }
  Point operator += (const Point &p) {
    x += p.x;
    y += p.y;
    return *this;
  }
  Point operator -= (const Point &p) {
    x -= p.x;
    y -= p.y;
    return *this;
  }
  Point operator *= (const ld k) {
    x *= k;
    y *= k;
    return *this;
  }
  Point operator /= (const ld k) {
    x /= k;
    y /= k;
    return *this;
  }
  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }
  bool operator == (const Point &p) const {
    return equals(x, p.x) && equals(y, p.y);
  }
  friend ostream& operator << (ostream &os, const Point &p) {
    os << p.x << ' ' << p.y;
    return os;
  }
  friend istream& operator >> (istream &is, Point &p) {
    ld x, y;
    is >> x >> y;
    p = Point(x, y);
    return is;
  }

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

ld dot(Point a, Point b) {
  return a.x * b.x + a.y * b.y;
}

ld cross(Point a, Point b) {
  return a.x * b.y - a.y * b.x;
}

class Segment {
public:
  Point p1, p2;

  Segment() {}
  Segment(Point p1, Point p2): p1(p1), p2(p2) {}

  friend ostream& operator << (ostream &os, const Segment &s) {
    os << s.p1 << ' ' << s.p2;
    return os;
  }
  friend istream& operator >> (istream &is, Segment &s) {
    Point p1, p2;
    is >> p1 >> p2;
    s = Segment(p1, p2);
    return is;
  }
};

//線分sに対する点pの射影
Point project(Segment s, Point p) {
  Point base = s.p2 - s.p1;
  ld r = dot(p - s.p1, base) / base.norm();
  return s.p1 + base * r;
}

//線分sを対称軸とした点pの線対象の点
Point reflect(Segment s, Point p) {
  return p + (project(s, p) - p) * 2;
}

//反時計回り:1
//時計回り:-1
//p2, p0, p1:2
//p0, p1, p2:-2
//p0, p2, p1:0
int ccw(Point p0, Point p1, Point p2) {
  Point a = p1 - p0;
  Point b = p2 - p0;
  if (cross(a, b) > EPS) return 1;
  if (cross(a, b) < -EPS) return -1;
  if (dot(a, b) < -EPS) return 2;
  if (a.norm() < b.norm()) return -2;
  return 0;
}

bool intersect(Point p1, Point p2, Point p3, Point p4) {
  return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}

bool intersect(Segment s1, Segment s2) {
  return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

//直線lと点pの距離
ld getDistanceLP(Segment l, Point p) {
  return abs(cross(l.p2 - l.p1, p - l.p1) / (l.p2 - l.p1).abs());
}

//線分sと点pの距離
ld getDistanceSP(Segment s, Point p) {
  if (dot(s.p2 - s.p1, p - s.p1) < 0) return (p - s.p1).abs();
  if (dot(s.p1 - s.p2, p - s.p2) < 0) return (p - s.p2).abs();
  return getDistanceLP(s, p);
}



class Circle {
public:
  Point p;
  ld r;

  Circle() {}
  Circle(Point p, ld r): p(p), r(r) {}
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  Segment s[2];
  int q;
  cin >> q;
  while (q--) {
    cin >> s[0] >> s[1];
    cout << intersect(s[0], s[1]) << '\n';
  }


  

  
  return 0;
}


Measured memory_bytes: 3300