#include<cstdio>
#include<vector>
#include<complex>
#include<utility>
using namespace std;
const double eps = 1e-10;
typedef complex<double> Point;
typedef Point Vector;
pair <Point,Point> Line1,Line2;

double dot(Point& a,Point& b)
{
    return real(conj(a)*b);
}

double cross(Point& a, Point& b)
{
    return imag(conj(a)*b);
}

int ccw(Point& a, Point& b, Point& c)
{
    Point t1 = b - a, t2 = c - a;
    if (cross(t1, t2) > 0)   return +1;       // counter clockwise
    if (cross(t1, t2) < 0)   return -1;       // clockwise
    if (dot(t1, t2) < 0)     return +2;       // c--a--b on line
    if (norm(t1) < norm(t2)) return -2;       // a--b--c on line
    return 0;
}

bool isintersaction(pair <Point,Point> a, pair <Point,Point> b)
{
    return (ccw(b.first,b.second,a.first)*ccw(b.first,b.second,a.second) <= 0 && ccw(a.first,a.second,b.first)*ccw(a.first,a.second,b.second) <= 0);
}

int main()
{
    int vol;
    scanf("%d",&vol);
    while(vol--)
    {
        int x0, y0, x1, y1, x2, y2, x3, y3;
        scanf("%d%d%d%d%d%d%d%d",&x0,&y0,&x1,&y1,&x2,&y2,&x3,&y3);
        Line1 = make_pair(Point(x0, y0), Point(x1, y1)), Line2 = make_pair(Point(x2, y2), Point(x3, y3));
        printf("%d\n",isintersaction(Line1, Line2));
    }
    return 0;
}
/*

1
0 0 5 0 1 0 1 2

*/
/*

00.00 sec    1056 KB    71 lines     1960 bytes    2013-07-31 16:54
#include <vector>
#include <complex>
#include <cstdio>
#include <cassert>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

int main(){
	int T,x1,y1,x2,y2;
	for(scanf("%d",&T);T--;){
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		L A(P(x1,y1),P(x2,y2));
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		L B(P(x1,y1),P(x2,y2));
		printf("%d\n",intersectSS(A,B));
	}
}



*/

Measured memory_bytes: 1048