#include <iostream>
#include <cmath>
using namespace std;

typedef pair<double,double>P;
#define X first
#define Y second

P sub(P a,P b){
	return P(a.X-b.X,a.Y-b.Y);
}

int chk(P a,P b,P c,P p){
	P ab=sub(b,a);
	P bp=sub(p,b);
	P bc=sub(c,b);
	P cp=sub(p,c);
	P ca=sub(a,c);
	P ap=sub(p,a);
	double c1 = ab.X * bp.Y - ab.Y * bp.X;
	double c2 = bc.X * cp.Y - bc.Y * cp.X;
	double c3 = ca.X * ap.Y - ca.Y * ap.X;
	if( ( c1 > 0 && c2 > 0 && c3 > 0 ) || ( c1 < 0 && c2 < 0 && c3 < 0 ) ) {
		//三角形の内側に点がある
		return 1;
	}
	return 0;
}

int main(){
	
	int n;cin>>n;
	while(n--){
		P a,b,c,d,e;
		cin>>a.X>>a.Y>>b.X>>b.Y>>c.X>>c.Y>>d.X>>d.Y>>e.X>>e.Y;
		if(chk(a,b,c,d)+chk(a,b,c,e)==1)cout<<"OK\n";
		else cout<<"NG\n";
		
	}
	return 0;
}
