#include<cstdio>
#include<complex>
typedef std::complex<double>P;
double C(P a,P b){return a.real()*b.imag()-a.imag()*b.real();}
int F(P p,P a,P b,P c)
{
	double x=C(b-a,p-a),y=C(c-b,p-b),z=C(a-c,p-c);
	return x>0&&y>0&&z>0||x<0&&y<0&&z<0;
}
int main()
{
	P p[5];
	int n,i,x,y;
	for(scanf("%d",&n);n--;)
	{
		for(i=0;i<5;++i)scanf("%d%d",&x,&y),p[i]=P(x,y);
		puts((F(p[3],p[0],p[1],p[2])^F(p[4],p[0],p[1],p[2]))?"OK":"NG");
	}
}