import std.stdio;
import std.math;

const double EPS = 1e-10;
double[3] xp, yp;

void main(){
	int n;
	double xk, yk, xs, ys;
	readf("%d\n", &n);
	for (int i = 0; i < n; i++) {
		readf("%s %s %s %s %s %s %s %s\n", &xp[0], &yp[0], &xp[1], &yp[1], &xp[2], &yp[2], &xk, &yk, &xs, &ys);
		if (inTriangle(xk, yk) + inTriangle(xs, ys) == 0) writeln("OK");
		else writeln("NG");
	}
}

// true -> 1, false -> -1
int inTriangle(double x, double y){
	double a, b, c, z, pa, pb, pc, Sa, Sb, Sc, Sp, S;
	a = dist(xp[1], yp[1], xp[2], yp[2]);
	b = dist(xp[2], yp[2], xp[0], yp[0]);
	c = dist(xp[0], yp[0], xp[1], yp[1]);
	S = heron(a, b, c);

	pa = dist(x, y, xp[0], yp[0]);
	pb = dist(x, y, xp[1], yp[1]);
	pc = dist(x, y, xp[2], yp[2]);
	Sa = heron(a, pb, pc);
	Sb = heron(pa, b, pc);
	Sc = heron(pa, pb, c);
	Sp = Sa + Sb + Sc;
	if (fabs(Sp-S) < EPS) return 1; // TODO
	else return -1;
}

double dist(double x1, double y1, double x2, double y2){
	return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

double heron(double a,double b,double c){
	double z = (a + b + c) / 2;
	return sqrt(z*(z-a)*(z-b)*(z-c));
}