// 2011/03/03 Tazoe

#include <iostream>
using namespace std;

int trian2(int x1, int y1, int x2, int y2)
{
	int s2 = x1*y2-x2*y1;

	if(s2<0)
		s2 = -s2;

	return s2;
}

bool insid(int x1, int y1, int x2, int y2, int x3, int y3, int x, int y)
{
	int s = trian2(x2-x1, y2-y1, x3-x1, y3-y1);

	int s1 = trian2(x1-x, y1-y, x2-x, y2-y);
	int s2 = trian2(x2-x, y2-y, x3-x, y3-y);
	int s3 = trian2(x3-x, y3-y, x1-x, y1-y);

	if(s==s1+s2+s3)
		return true;
	else
		return false;
}

int main()
{
	int n;
	cin >> n;

	for(int i=0; i<n; i++){
		int xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
		cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;

		bool ink = insid(xp1, yp1, xp2, yp2, xp3, yp3, xk, yk);
		bool ins = insid(xp1, yp1, xp2, yp2, xp3, yp3, xs, ys);

		if(ink!=ins)
			cout << "OK" << endl;
		else
			cout << "NG" << endl;
	}

	return 0;
}