#include <stdio.h>

int intsec_line( double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double *x, double *y ) {
	double tmp;
	double a, b, c, d;
	int rel;

	if ( x1 < x0 ) {
		tmp = x0;
		x0 = x1;
		x1 = tmp;

		tmp = y0;
		y0 = y1;
		y1 = tmp;
	}
	if ( x3 < x2 ) {
		tmp = x2;
		x2 = x3;
		x3 = tmp;

		tmp = y2;
		y2 = y3;
		y3 = tmp;
	}

	if ( x0 != x1 ) {
		a = ( y0 - y1 ) / ( x0 - x1 );
		b = ( x0 * y1 - x1 * y0 ) / ( x0 - x1 );
	}
	if ( x2 != x3 ) {
		c = ( y2 - y3 ) / ( x2 - x3 );
		d = ( x2 * y3 - x3 * y2 ) / ( x2 - x3 );
	}

	rel = 1;
	if ( x0 == x1 ) {
		*x = x0;
		if ( x2 == x3 )
			rel = 2;
		else {
			*y = c * *x + d;
			if ( *x < x2 || x3 < *x || *y < ( y0 < y1 ? y0 : y1 ) || ( y0 < y1 ? y1 : y0 ) < *y )
				rel = 0;
		}
	} else {
		if ( x2 == x3 ) {
			*x = x2;
			*y = a * *x + b;
			if ( *x < x0 || x1 < *x || *y < ( y2 < y3 ? y2 : y3 ) || ( y2 < y3 ? y3 : y2 ) < *y )
				rel = 0;
		} else
			if ( a == c )
				rel = 2;
			else {
				*x = ( -b + d ) / ( a - c );
				*y = a * *x + b;
				if ( *x < x0 || x1 < *x || *x < x2 || x3 < *x )
					rel = 0;
			}
	}

	return rel;
}


int main( void ) {
	int q;

	scanf( "%d", &q );
	while ( q-- ) {
		double x0, y0, x1, y1, x2, y2, x3, y3, x, y;

		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3 );
		printf( "%d\n", intsec_line( x0, y0, x1, y1, x2, y2, x3, y3, &x, &y ) );
	}

	return 0;
}