#include <iostream>
#include <cstdio>

struct P{
	double x, y;
};

typedef P Vector;

struct Triangle{
	P ps[3];
};

int crossProduct(Vector v1, Vector v2){
	return v1.x*v2.y - v1.y*v2.x;
}

Vector pToVector(P p1, P p2){
	return {p1.x-p2.x, p1.y-p2.y};
}

bool triangle_contains(Triangle t, P p){
	int count = 0;
	for(int i=0;i<3;i++){
		Vector a = pToVector(t.ps[i], t.ps[(i+1)%3]),
			b = pToVector(p, t.ps[i]);
		if(crossProduct(a, b) > 0)count++;
		else count--;
	}
	return (count%3 != 0);
}

int main(){
	int n;
	std::cin >> n;
	for(;n--;){
		P ps[3], k, s;
		for(int i=0;i<3;i++){
			std::cin >> ps[i].x >> ps[i].y;
		}
		std::cin >> k.x >> k.y >> s.x >> s.y;
		Triangle t;
		for(int i=0;i<3;i++){
			t.ps[i] = ps[i];
		}
		bool k_contains = triangle_contains(t, k),
			s_contains = triangle_contains(t, s);
		if(k_contains != s_contains){
			puts("OK");
		}else{
			puts("NG");
		}
	}
}