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

struct point{
	double x, y;
};

vector<point> t(3);

bool isIn(point s) {
	point a, b, c;
	a.x = t[1].x-t[0].x; a.y = t[1].y-t[0].y;
	b.x = t[2].x-t[0].x; b.y = t[2].y-t[0].y;
	c.x = s.x-t[0].x; c.y = s.y-t[0].y;
	double c1, c2;
	c1 = (b.y*c.x - b.x*c.y) / (a.x*b.y - a.y*b.x);
	c2 = (a.y*c.x - a.x*c.y) / (a.y*b.x - a.x*b.y);
	if ((c1>0.0)&&(c2>0.0)&&(c1+c2<1.0)) return true;
	return false;
}

int main()
{
	int n, i;
	point s, g;
	cin>>n;
	for (i = 0; i < n; i++) {
		cin>>t[0].x>>t[0].y>>t[1].x>>t[1].y>>t[2].x>>t[2].y;
		cin>>s.x>>s.y>>g.x>>g.y;
		if (isIn(s)^isIn(g)) cout<<"OK"<<endl;
		else cout<<"NG"<<endl;
	}
	return 0;
}