#include <iostream>

using namespace std;

struct P{
	double x;
	double y;
};

int ccw(P p0, P p1, P p2)
{
	double dx1 = p1.x-p0.x;
	double dy1 = p1.y-p0.y;
	double dx2 = p2.x-p0.x;
	double dy2 = p2.y-p0.y;
	
	if(dx1*dy2 > dy1*dx2){
		return 1;
	} 
	if(dx1*dy2 < dy1*dx2){
		return -1;
	}
	if((dx1*dx2 < 0) || (dy1*dy2 < 0)){
		return -1;
	}
	if((dx1*dx1+dy1*dy1)<(dx2*dx2+dy2*dy2)){
		return 1;
	}
	
	return 0;
}

int intersect(P p1, P p2, P p3, P p4)
{
	return (((ccw(p1, p2, p3)*ccw(p1, p2, p4)) <= 0)
				 &&((ccw(p3, p4, p1)*ccw(p3, p4, p2)) <= 0));
}

int main()
{
	int n, c;
	bool f;
	P pr[3], s, t;
	
	while(cin>>n && n){
		while(n--){
			c = 0;
			cin >> pr[0].x >> pr[0].y >> pr[1].x >> pr[1].y >> pr[2].x >> pr[2].y >> s.x >> s.y >> t.x >> t.y;
			if(intersect(pr[0], pr[1], s, t) == 1){
				c++;
			}
			if(intersect(pr[0], pr[2], s, t) == 1){
				c++;
			}
			if(intersect(pr[1], pr[2], s, t) == 1){
				c++;
			}
			if(c == 1){
				cout << "OK" << endl;
			} else {
				cout << "NG" << endl;
			}
		}
	}
	
	return 0;
}