#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
#define EPS 1e-10

double add(double a,double b)
{
	if(abs(a+b)<EPS*(abs(a)+abs(b)))return 0;
	return a+b;
}
typedef struct Vec{
	double x,y;
	Vec(){}
	Vec( double x,double y):x(x),y(y){}
	Vec operator +(Vec v){return Vec(add(x,v.x),add(y,v.y));}
	Vec operator -(Vec v){return Vec(add(x,-v.x),add(y,-v.y));}
	Vec operator *(double d){return Vec(x*d,y*d);}
	double dot(Vec v){return add(x*v.x,y*v.y);}
	double det(Vec v){return add(x*v.y,-y*v.x);}
}V;


bool on_seg(Vec p1,Vec p2,Vec q)
{
	return (p1-q).det(p2-q)==0&&(p1-q).dot(p2-q)<=0;
}

Vec intersection(Vec p1,Vec p2,Vec q1,Vec q2)
{
	return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));
}

Vec A,B;
int N,p=1,c=0;
Vec pos[3];

void check(Vec f,Vec e)
{
	if((B-A).det(e-f)!=0)
	{
		Vec r=intersection(A,B,f,e);
		if(on_seg(A,B,r)&&on_seg(f,e,r))
		{
			c++;
		}
	}
}

int main()
{
	int N;
	scanf("%d",&N);
	for(;N--;)
	{
		c=0;
		for(int i=0;i<3;i++)
			scanf("%lf%lf",&pos[i].x,&pos[i].y);
		scanf("%lf%lf",&A.x,&A.y);
		scanf("%lf%lf",&B.x,&B.y);
		for(int i=0;i<3;i++)
			check(pos[i],pos[(i+1)%3]);
		puts(c==1?"OK":"NG");
	}
}