#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
typedef pair<double, double> P;
const double eps = 1e-9;

double Length(P p1, P p2)
{
	return(sqrt((p1.first - p2.first) * (p1.first - p2.first) + (p1.second - p2.second) * (p1.second - p2.second)));
}

double Helon(P p1, P p2, P p3)
{
	double a = Length(p1, p2);
	double b = Length(p2, p3);
	double c = Length(p3, p1);
	double s = (a + b + c) / 2;
	return(sqrt(s * (s - a) * (s - b) * (s - c)));
}

void solve()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i)
	{
		vector<P> Point(3);
		P pk, ps;
		for(int j = 0; j < 3; ++j)
		{
			cin >> Point[j].first >> Point[j].second;
		}
		cin >> pk.first >> pk.second >> ps.first >> ps.second;
		double S = Helon(Point[0], Point[1], Point[2]);
		double S1 = Helon(Point[0], Point[1], pk);
		S1 += Helon(Point[1], Point[2], pk);
		S1 += Helon(Point[2], Point[0], pk);

		double S2 = Helon(Point[0], Point[1], ps);
		S2 += Helon(Point[1], Point[2], ps);
		S2 += Helon(Point[2], Point[0], ps);

		if(fabs(S - S1) < eps && fabs(S - S2) >= eps || fabs(S - S1) >= eps && fabs(S - S2) < eps)
		{
			cout << "OK" << endl;
		}
		else
		{
			cout << "NG" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}