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

typedef complex<double> P;

#define EPS (1e-10)

double cross(P a,P b){
	return (a.real() * b.imag() - a.imag() * b.real());
}

int is_intersected_ls(P a1,P a2,P b1,P b2){
	return ((cross(a2-a1,b1-a1) * cross(a2-a1,b2-a1) < EPS) &&
					(cross(b2-b1,a1-b1) * cross(b2-b1,a2-b1) < EPS));
}

int main(void){
	int n;
	cin>>n;

	while(n--){
		P p[3],k,s;

		for(int i=0;i<3;i++){
			cin>>p[i].real()>>p[i].imag();
		}
		cin>>k.real()>>k.imag();
		cin>>s.real()>>s.imag();

		int count = 0;
		count += is_intersected_ls(k,s,p[0],p[1]);
		count += is_intersected_ls(k,s,p[1],p[2]);
		count += is_intersected_ls(k,s,p[2],p[0]);

		if(count == 1){
			cout<<"OK\n";
		}
		else{
			cout<<"NG\n";
		}
	}

	return 0;
}