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

struct Point
{
	Point(int x, int y):x(x),y(y),z(0){}
	Point():x(0),y(0),z(0){}
	int x,y,z;
};
inline bool isLeft( Point &p, Point &a, Point &b ){
	return ( (b.x-a.x)*(p.y-a.y) - (b.y-a.y)*(p.x-a.x) ) > 0;
}
bool isInside( Point &p, vector<Point> &vp ){
	bool bCond = isLeft( p, vp[0], vp[1] );
	for(unsigned int i = 1; i < vp.size(); ++i){
		if( bCond != isLeft( p, vp[i-1], vp[i] ) )
			return false;
	}
	return bCond == isLeft( p, vp[vp.size()-1], vp[0] );
}

int main()
{
	int n;
	cin >> n;
	for(int X = 0; X < n; ++X ){
		Point A, B, C, ken, ori;
		bool  bKenInside = false, bOriInside = false;
		vector<Point> triangle;
		cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y >> ken.x >> ken.y >> ori.x >> ori.y;
		triangle.push_back(A);triangle.push_back(B);triangle.push_back(C);

		bKenInside = isInside( ken, triangle );
		bOriInside = isInside( ori, triangle );
		if( bKenInside ^ bOriInside )
			cout << "OK\n";
		else
			cout << "NG\n";
	}
	return 0;
}