#include <iostream>
using namespace std;

class Vector2
{
public:
	Vector2() : x( 0 ), y( 0 ){}
	Vector2( int _x, int _y ) : x( _x ), y( _y ){}
	Vector2& operator=( const Vector2& v )
	{
		this->x = v.x;
		this->y = v.y;
		return *this;
	}
	Vector2 operator-( const Vector2& v )
	{
		Vector2 ret;
		ret.x = this->x - v.x;
		ret.y = this->y - v.y;
		return ret;
	}
	int clossProduct( const Vector2& v )
	{
		return this->x * v.y - this->y * v.x;
	}

	int x, y;
};

bool solve()
{
	Vector2 coodi[ 5 ];
	for( int i = 0; i < 5; ++i ){
		Vector2 v;
		cin >> v.x >> v.y;
		coodi[ i ] = v;
	}
	int closs[ 2 ][ 3 ];
	for( int i = 0; i < 2; ++i ){
		Vector2& o = coodi[ 3 + i ];
		for( int j = 0; j < 3; ++j ){
			Vector2 v = coodi[ ( j + 1 ) % 3 ] - coodi[ j ];
			Vector2 w = o - coodi[ j ];
			closs[ i ][ j ] = v.clossProduct( w );
		}
	}
	for( int i = 0; i < 2; ++i ){
		int a = closs[ i ][ 0 ] * closs[ i ][ 1 ];
		int b = closs[ i ][ 1 ] * closs[ i ][ 2 ];
		int c = closs[ i ][ 2 ] * closs[ i ][ 0 ];
		closs[ i ][ 0 ] = a;
		closs[ i ][ 1 ] = b;
		closs[ i ][ 2 ] = c;
	}
	if( ( ( closs[ 0 ][ 0 ] > 0 && closs[ 0 ][ 1 ] > 0 && closs[ 0 ][ 2 ] > 0 )
		&& ( closs[ 1 ][ 0 ] < 0 || closs[ 1 ][ 1 ] < 0 || closs[ 1 ][ 2 ] < 0 ) )
		|| ( ( closs[ 0 ][ 0 ] < 0 || closs[ 0 ][ 1 ] < 0 || closs[ 0 ][ 2 ] < 0 )
		&& ( closs[ 1 ][ 0 ] > 0 && closs[ 1 ][ 1 ] > 0 && closs[ 1 ][ 2 ] > 0 ) ) ){
		return true;
	}
	return false;
}

int main()
{
	int n;
	while( cin >> n ){
		for( int i = 0; i < n; ++i ){
			if( solve() ){
				cout << "OK" << endl;
			}else{
				cout << "NG" << endl;
			}
		}
	}

	return 0;
}