/* Header {{{ */
#include <bits/stdc++.h>
using namespace std;

typedef long long readtype;
typedef long long var;
typedef long double let;

readtype read() {
  readtype a = 0, c = getchar(), s = 0;
  while (!isdigit(c)) s |= c == '-', c = getchar();
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return s ? -a : a;
}

#ifdef LOCAL_LOGGER
#define logger(...) fprintf(stderr, __VA_ARGS__)
#define abortif(v, ...) if (v) {logger("Error in Line %d, Function '%s()'.\nInfo: ", __LINE__, __FUNCTION__); logger(__VA_ARGS__); exit(0);}
#else
#define logger(...);
#define abortif(v, ...);
#endif
/* }}} */

const let EPS = 1e-8;

int sign(let x) { return (x < -EPS) ? -1 : (x > EPS ? 1 : 0); }

struct Point {
  let x, y;
  friend Point operator + (Point a, Point b) {
    return (Point) {a.x + b.x, a.y + b.y};
  }
  friend Point operator - (Point a, Point b) {
    return (Point) {a.x - b.x, a.y - b.y};
  }
  friend let Times(Point a, Point b) {
    return a.x * b.y - a.y * b.x;
  }
  Point operator * (let k) { return (Point) {x * k, y * k}; }
  Point operator ~ () {
    return (Point) {x, -y};
  }
  Point Rotate(let sink, let cosk) {
    return (Point) {
      x * cosk - y * sink, x * sink + y * cosk
    };
  }
  let dist() {
    return sqrt(x * x + y * y);
  }
};

typedef Point Vec;

struct Segment {
  Point s, e;
  Vec v;

  Segment() {}
  Segment(Point a, Point b) {
    s = a, e = b;
    v = b - a;
  }
  Segment(Point a, Point b, Vec c) {
    s = a, e = b, v = c;
  }

  Segment Rotate(Vec v) {
    let z = v.dist();
    return Rotate(v.y / z, v.x / z);
  }

  Segment Rotate(let sink, let cosk) {
    return (Segment) {
      s.Rotate(sink, cosk), e.Rotate(sink, cosk), v.Rotate(sink, cosk)
    };
  }

  Segment operator + (Vec b) {
    return (Segment) {s + b, e + b, v};
  }

  Segment operator - (Vec b) {
    return (Segment) {s - b, e - b, v};
  }

  friend bool CheckIntersection(Segment a, Segment b) {
    let ar = a.v.dist();
    Segment c = (b - a.s).Rotate(~a.v);

    int tcs = sign(Times(c.s, (Point) {ar, 0})),
        tce = sign(Times(c.e, (Point) {ar, 0}));

    if (tcs == 0 && tce == 0) {
      if (sign(max(c.s.x, c.e.x)) < 0 ||
          sign(min(c.s.x, c.e.x) - ar) > 0) return false;
      return true;
    }

    if (tcs == tce) return false;

    Point i = c.e - c.v * (c.e.y / c.v.y);
    if (sign(i.x) < 0 || sign(i.x - ar) > 0) return false;
    return true;
  }
};

Point ReadPoint() {
  Point t;
  scanf("%Lf%Lf", &t.x, &t.y);
  return t;
}

int main() {
// #ifndef ONLINE_JUDGE
//   freopen("CGL_2_B.in", "r", stdin);
//   freopen("CGL_2_B.out", "w", stdout);
// #endif
// #ifdef LOCAL_LOGGER
//   freopen("CGL_2_B.log", "w", stderr);
// #endif
  int q = read();
  while (q--) {
    Point p0 = ReadPoint(),
          p1 = ReadPoint(),
          p2 = ReadPoint(),
          p3 = ReadPoint();
    Segment s1 = (Segment) {p0, p1},
            s2 = (Segment) {p2, p3};
    if (CheckIntersection(s1, s2))
      puts("1");
    else puts("0");
  }
  return 0;
}

/* ==== Makefile ==== {{{
CompileAndRun:
	make Compile
	make Run

Compile:
	g++ -o CGL_2_B CGL_2_B.cpp -g -Wall -DLOCAL_LOGGER

CompileUF:
	g++ -o CGL_2_B CGL_2_B.cpp -g -Wall -DLOCAL_LOGGER -fsanitize=undefined

Run:
	./CGL_2_B < CGL_2_B.in > CGL_2_B.out
==================
}}} */



Measured memory_bytes: 3224