import std.stdio;
import std.typecons;
import std.string;
import std.conv;
import std.math;

alias Tuple!(real, "x", real, "y") Point;
alias Point Vector;

void main(){
	int n;
	readf("%d\n", &n);
	for(int i=0;i<n;i++){
		string s = readln();
		string[] ss = s.split();
		Point[5] p;
		for(int j=0;j<5;j++){
			p[j].x = ss[2*j].to!(real);
			p[j].y = ss[2*j+1].to!(real);
		}

		Vector[3] v;
		int res[2];
		for(int k=0;k<2;k++){
			for(int j=0;j<3;j++){
				v[j].x = p[j].x-p[3+k].x;
				v[j].y = p[j].y-p[3+k].y;
			}
			real[3] cp;
			for(int j=0;j<3;j++){
				cp[j] = v[j].x*v[(j+1)%3].y-v[j].y*v[(j+1)%3].x;
			}
			res[k] = (cp[0]<0) + (cp[1]<0) + (cp[2]<0)%3 == 0;
		}
		if(res[0] == 0 && res[1] == 1)writeln("OK");
		else writeln("NG");
	}
}