/**************** Geometrical Library ****************/

#include<cmath>
#include<vector>
#include<algorithm>

#define	EPS	1e-9

enum {CCW=1,CW=-1,ON=0};

#define	mp	make_pair
#define	pb	push_back

using namespace std;

class Point{
public:
	double x,y;
	Point(){}
	Point(double xx,double yy):x(xx),y(yy){}
};

class Line:public vector<Point>{
public:
	Line(const Point &a,const Point &b){
		pb(a),pb(b);
	}
};

class Segment:public Line{
public:
	Segment(const Point &a,const Point &b):Line(a,b){}
};

class Polygon:public vector<Point>{};

class Circle{
public:
	Point c;
	double r;
	Circle(const Point &cc,double rr) : c(cc),r(rr){}
};

Point &operator +=(Point &a,const Point &b){
	a.x+=b.x,a.y+=b.y;
	return a;
}

Point &operator -=(Point &a,const Point &b){
	a.x-=b.x,a.y-=b.y;
	return a;
}

Point &operator *=(Point &a,double c){
	a.x*=c,a.y*=c;
	return a;
}

Point &operator /=(Point &a,double c){
	a.x/=c,a.y/=c;
	return a;
}

Point operator +(const Point &a,const Point &b){
	Point c=a;
	return c+=b;
}

Point operator -(const Point &a,const Point &b){
	Point c=a;
	return c-=b;
}

Point operator *(double c,const Point &a){
	Point b=a;
	return b*=c;
}

Point operator /(const Point &a,double c){
	Point b=a;
	return b/=c;
}

bool operator <(const Point &a,const Point &b){
	return (a.x==b.x)?(a.y<b.y):(a.x<b.x);
}

bool operator >(const Point &a,const Point &b){
	return b<a;
}

double cross(const Point &a,const Point &b){
	return a.x*b.y-a.y*b.x;
}

int ccw(const Point &a,Point b,Point c){
	b-=a,c-=a;
	double rotdir=cross(b,c);
	if(rotdir>EPS)		return CCW;
	if(rotdir<-EPS)		return CW;
	return ON;
}

/**************** Library END ****************/

#include<cstdio>

int main(){
	int n;	scanf("%d",&n);
	while(n--){
		Point a,b,c,star[2];
		scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
			&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&star[0].x,&star[0].y,&star[1].x,&star[1].y);
		bool in[2];
		for(int i=0;i<2;i++){
			int cnt=0;
			cnt+=ccw(a,b,star[i]);
			cnt+=ccw(b,c,star[i]);
			cnt+=ccw(c,a,star[i]);
			in[i]=(cnt==3*CCW || cnt==3*CW);
		}
		puts(in[0]==in[1]?"NG":"OK");
	}
	return 0;
}