#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int get() { int r; cin >> r; return r; }
void solve() {
	double x[5], y[5], xs, ys, xt, yt;
	cin >> x[1] >> y[1] >> x[2] >> y[2] >> x[0] >> y[0] >> xs >> ys >> xt >> yt;
	int i1 = 1, i2 = 1, a = 1, b = 2, c = 0;
	for1(i, 3) {
		if (((x[a] - x[b]) * (ys - y[a]) - (y[a] - y[b]) * (xs - x[a])) * ((x[a] - x[b]) * (y[c] - y[a]) - (y[a] - y[b]) * (x[c] - x[a])) < 0)i1 = 0;
		if (((x[a] - x[b]) * (yt - y[a]) - (y[a] - y[b]) * (xt - x[a])) * ((x[a] - x[b]) * (y[c] - y[a]) - (y[a] - y[b]) * (x[c] - x[a])) < 0)i2 = 0;
		a++; b++; c++;
		if (a >= 3)a %= 3;
		if (b >= 3)b %= 3;
		if (c >= 3)c %= 3;
	}
	cout << (i1 + i2 == 1 ? "OK\n" : "NG\n");
}
signed main() {
	int n; cin >> n; for1(i, n)solve();
}
