#include <stdio.h>
#include <math.h>

double get_radian(double x1, double y1, double x2, double y2) {
	if(fabs(x1-x2) < 0.00000001f) {
		if(fabs(y1-y2) < 0.00000001f) {
			return 0.0f;
		} else if(y1 > y2) {
			return 3 * M_PI / 2;
		} else {
			return M_PI / 2;
		}
	} else if(fabs(y1-y2) < 0.00000001f) {
		if(fabs(x1-x2) < 0.00000001f) {
			return 0.0f;
		} else if(x1 > x2) {
			return M_PI;
		}
		return 0.0;
	}
	
	if(x2 >= x1) {
		if(y2 >= y1) {
			return atan((y2-y1)/(x2-x1));
		}
		return 2 * M_PI + atan((y2-y1)/(x2-x1));
	} else {
		if(y2 >= y1) {
			return M_PI - atan((y2-y1)/(x1-x2));
		}
		return M_PI + atan((y2-y1)/(x2-x1));
	}
}

int is_crossing_line(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4){
	double S,T,D;

	//	分母を先に計算。計算量を減らすため、分子は後で行う。
	D = (x3-x1) * (y4-y1) - (y3-y1) * (x4-x1);
	
	//	D の符号に応じて分岐
	if(D < 0){
		S = (y4-y1)*(x2-x1) - (x4-x1)*(y2-y1);
		T = (x3-x1)*(y2-y1) - (y3-y1)*(x2-x1);
		
		return S <= 0 && T <= 0 && (S+T)/D >= 1;
	}
	else if(D > 0){
		S = (y4-y1)*(x2-x1) - (x4-x1)*(y2-y1);
		T = (x3-x1)*(y2-y1) - (y3-y1)*(x2-x1);
		
		return S >= 0 && T >= 0 && (S+T)/D >= 1;
	}
	
	//	D = 0 の時には、点が線分の上かどうかを判定する。
	return (x3-x1)*(x4-x1)+(y3-y1)*(y4-y1) <= 0
	    || (x3-x2)*(x4-x2)+(y3-y2)*(y4-y2) <= 0
	    || (x1-x3)*(x2-x3)+(y1-y3)*(y2-y3) <= 0;
}

int main(void) {
	double x1,x2,x3,x4,y1,y2,y3,y4;
	double ta, tb, tc, td;
	int i, n;
	
	scanf("%d\n", &n);
	for(i=0;i<n;i++) {
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf\n", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);

		if(is_crossing_line(x1, y1, x2, y2, x3, y3, x4, y4)) {
			printf("1\n");
		} else {
			printf("0\n");
		}
	}
	
	return 0;
}