#include <cmath>
#include <complex>
#include <vector>
#include <cstdio>
using namespace std;


#define EPS 1e-7


typedef complex<double> point;
typedef vector<point> polygon;


bool contains(const polygon &plg, const point &pt){
	int cnt = 0;
	double y = imag(pt);

	for(int i = 1; i < plg.size(); ++i){
		double dyi = imag(plg[i]) - y;
		double dyj = y - imag(plg[i-1]);
		double tx = (dyi * real(plg[i-1]) + dyj * real(plg[i])) / (dyi + dyj);

		if(imag(plg[i]) >= y && imag(plg[i-1]) < y){
			if( tx < real(pt) ) ++cnt;
		}
		else if(imag(plg[i]) < y && imag(plg[i-1]) >= y){
			if( tx < real(pt) ) ++cnt;
		}
	}
	
	return (cnt % 2 != 0);
}


int main(){
	int n;
	int x, y;
	vector<point> tri(4);
	
	for(scanf("%d", &n); n--; ){
		for(int i = 0; i < 3; ++i){
			scanf("%d%d", &x, &y);
			tri[i] = point(x, y);
		}
		tri[3] = tri[0];

		scanf("%d%d", &x, &y);
		point pk(x, y);
		scanf("%d%d", &x, &y);
		point ps(x, y);
		
		if( contains(tri, pk) != contains(tri, ps) ){
			puts("OK");
		}
		else{
			puts("NG");
		}
	}
}