#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

bool
intersect(double xs0, double ys0, double xs1, double ys1, double xt0, double yt0, double xt1, double yt1)
{
	double rx1 = xs1 - xs0;
	double ry1 = ys1 - ys0;
	double rx2 = xt1 - xt0;
	double ry2 = yt1 - yt0;

	double ra = (rx1 * (ys0 - yt0) - ry1 * (xs0 - xt0)) / (rx1 * ry2 - rx2 * ry1);
	double rb = (rx2 * (xs0 - yt0) - ry2 * (xs0 - xt0)) / (rx1 * ry2 - rx2 * ry1);
	return (0 <= ra && ra <= 1 && 0 <= rb && rb <= 1);
}

int
main(int argc, char** argv)
{
	double xs0, ys0, xs1, ys1, xt0, yt0, xt1, yt1;
	int xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3;
	int q;

	scanf("%d", &q);
	while (q--)
	{
		scanf("%d %d %d %d %d %d %d %d", &xp0, &yp0, &xp1, &yp1, &xp2, &yp2, &xp3, &yp3);
		xs0 = xp0, ys0 = yp0;
		xs1 = xp1, ys1 = yp1;
		xt0 = xp2, yt0 = yp2;
		xt1 = xp3, yt1 = yp3;

		if (intersect(xs0, ys0, xs1, ys1, xt0, yt0, xt1, yt1))
			printf("1\n");
		else
			printf("0\n");
	}

	return 0;
}