#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>

using namespace std;

const double kEps = 1e-10;
const double kInf = 1e15;

int dcmp(double x) {
  if (fabs(x) < kEps) return 0;
  return x < 0 ? -1 : 1;
}

struct Vector {
  double x, y;
  Vector() {}
  Vector(double x, double y): x(x), y(y) {}
  // Vector(const Point & p1, const Point & p2): x(p2.x - p1.x), y(p2.y - p1.y) {}
  Vector(const Vector & v);

  double Norm() const { return hypot(x, y); }
  double NormSquared() const { return x * x + y * y; }
  Vector Normalize() const {
    return *this / this->Norm();
  }
  Vector operator-() const {
    return Vector(-x, -y);
  }
  Vector operator+(const Vector & rhs) const {
    return Vector(x + rhs.x, y + rhs.y);
  }
  Vector operator-(const Vector & rhs) const {
    return *this + (-rhs);
  }
  Vector operator*(const double rhs) const {
    return Vector(rhs * x, rhs * y);
  }
  Vector operator/(const double rhs) const {
    return *this * (1.0 / rhs);
  }
  double Dot(const Vector & rhs) const {
    return x * rhs.x + y * rhs.y;
  }
  double Cross(const Vector & rhs) const {
    return x * rhs.y - y * rhs.x;
  }
  bool operator==(const Vector & rhs) const {
    return dcmp(x - rhs.x) == 0 && dcmp(y - rhs.y) == 0;
  }
  bool operator<(const Vector & rhs) const {
    return dcmp(x - rhs.x) < 0 || (dcmp(x - rhs.x) == 0 && dcmp(y - rhs.y) < 0);
  }
};

struct Point {
  Point() {}
  Point(double x, double y): x(x), y(y) {}
  Point(const Point & p);

  double x, y;

  Point operator-() {
    return Point(-x, -y);
  }
  Point operator+(const Vector & rhs) const {
    return Point(x + rhs.x, y + rhs.y);
  }
  Point operator-(const Vector & rhs) const {
    return *this + (-rhs);
  }
  bool operator==(const Point & rhs) const {
    return dcmp(x - rhs.x) == 0 && dcmp(y - rhs.y) == 0;
  }
  bool operator<(const Point & rhs) const {
    return dcmp(x - rhs.x) < 0 || (dcmp(x - rhs.x) == 0 && dcmp(y - rhs.y) < 0);
  }
};

struct Line {
  Line() {}
  Line(const Point & p1, const Point & p2): p1(p1), p2(p2) {
    if (dcmp(p2.x - p1.x) == 0) {
      slope = kInf;
    } else {
      slope = (p2.y - p1.y) / (p2.x - p1.x);
    }
  }
  Line(double x1, double y1, double x2, double y2): p1(x1, y1), p2(x2, y2) {
    if (dcmp(x2 - x1) == 0) {
      slope = kInf;
    } else {
      slope = (y2 - y1) / (x2 - x1);
    }
  }
  Line(const Line & l);

  Point p1, p2;
  double slope;
};

// minus: left, plus: right, 0: colinear
int Direction(const Point & p0, const Point & p1, const Point & p2) {
  Vector v1(p1.x - p0.x, p1.y - p0.y);
  Vector v2(p2.x - p0.x, p2.y - p0.y);
  return dcmp(v2.Cross(v1));
}

// minus: back, plus: front, 0: on
int SegmentDirection(const Point & p0, const Point & p1, const Point & p2) {
  if (p2.x >= min(p0.x, p1.x) && p2.x <= max(p0.x, p1.x)
      && p2.y >= min(p0.y, p1.y) && p2.y <= max(p0.y, p1.y)) { return 0; }
  if ((p2.x - p0.x) * (p1.x - p0.x) > 0
      || (p2.y - p0.y) * (p1.y - p0.y) > 0) { return 1; }
  return -1;
}

bool IsIntersecting(const Line & l1, const Line & l2) {
  auto d1 = Direction(l2.p1, l2.p2, l1.p1);
  auto d2 = Direction(l2.p1, l2.p2, l1.p2);
  auto d3 = Direction(l1.p1, l1.p2, l2.p1);
  auto d4 = Direction(l1.p1, l1.p2, l2.p2);

  if (d1 * d2 < 0 && d3 * d4 < 0) { return true; }
  if (d1 == 0 && SegmentDirection(l2.p1, l2.p2, l1.p1) == 0) { return true; }
  if (d2 == 0 && SegmentDirection(l2.p1, l2.p2, l1.p2) == 0) { return true; }
  if (d3 == 0 && SegmentDirection(l1.p1, l1.p2, l2.p1) == 0) { return true; }
  if (d4 == 0 && SegmentDirection(l1.p1, l1.p2, l2.p2) == 0) { return true; }
  return false;
}

int main(int argc, char const *argv[]) {
  double x0, y0, x1, y1;
  Point p0(x0, y0);
  Point p1(x1, y1);

  int q;
  cin >> q;
  for (unsigned i = 0; i < q; ++i) {
    double x0, y0, x1, y1, x2, y2, x3, y3;
    cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

    if (IsIntersecting(Line(x0, y0, x1, y1), Line(x2, y2, x3, y3))) {
      cout << 1 << "\n";
    } else {
      cout << 0 << "\n";
    }
  }
  return 0;
}

Measured memory_bytes: 3212