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

#define x first 
#define y second 

typedef pair<double,double> pdd;

bool inTriangle(pdd o, pdd tri0, pdd tri1, pdd pts) {
	pdd a, b, c;
	a.x = tri0.x - o.x;
	a.y = tri0.y - o.y;
	b.x = tri1.x - o.x;
	b.y = tri1.y - o.y;
	c.x = pts.x - o.x;
	c.y = pts.y - o.y;

	double s, t;
	t = (c.x * a.y - c.y * a.x) / (b.x * a.y - b.y * a.x);
	s = (c.x * b.y - c.y * b.x) / (b.y * a.x - b.x * a.y);

	if(s >= 0 && t >= 0 && s + t <= 1)
		return true;
	return false;
}

int main() {
	int n;
	cin >> n;
	for(int t = 0; t < n; t++) {
		pdd in[5];
		for(int i = 0; i < 5; i++) {
			cin >> in[i].x >> in[i].y;
		}

		bool flag;
		flag = inTriangle(in[0], in[1], in[2], in[3]) ^ inTriangle(in[0], in[1], in[2], in[4]);
		if(flag)
			cout << "OK" << endl;
		else
			cout << "NG" << endl;
	}
}