#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

#define EPS (1e-8)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) ( EQ(a.real(), b.real()) && EQ(a.imag(), b.imag()) )

typedef complex<double> p;

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

int main() {
	int n;
	cin >> n;
	while (n--) {
		p point[5];
		REP(i, 5) {
			double a, b;
			scanf("%lf %lf", &a, &b);
			point[i] = p(a, b);
		}
		int cnt[2] = {};
		
		REP(i, 3) {
			p v[2];
			v[0] = point[(i + 1) % 3] - point[i];
			v[1] = point[3] - point[i];
			if (cross(v[0], v[1]) < -EPS) cnt[0]++;
			
			v[1] = point[4] - point[i];
			if (cross(v[0], v[1]) < -EPS) cnt[1]++;
		}
		bool flag[2];
		REP(i, 2) flag[i] = cnt[i] == 0 || cnt[i] == 3;
		if (flag[0] == !flag[1]) puts("OK");
		else puts("NG");
	}
	return 0;
}