#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <vector>

#define rep2(i, b, n) for(int i=b; i < n; ++i)
#define repm(i, b, n) for(int i=b; i > n; --i)
#define rep(i, n) rep2(i, 0, n)

using namespace std;

double cross_product( double x1, double y1, double x2, double y2 )
{
	return ((x1 * y2) - (x2 * y1));
}

int main( void )
{
	int n;
	
	while (cin >> n)
	{
		for (int i=0; i < n; ++i)
		{
			double x1, y1, x2, y2, x3, y3, xk, yk, xs, ys;
			cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3
				>> xk >> yk >> xs >> ys;
			
			double v1, v2, v3, v4, v5, v6;
		
			v1 = cross_product((x2-x1), (y2-y1), (xk-x1), (yk-y1));
			v2 = cross_product((x3-x2), (y3-y2), (xk-x2), (yk-y2));
			v3 = cross_product((x1-x3), (y1-y3), (xk-x3), (yk-y3));
		
			v4 = cross_product((x2-x1), (y2-y1), (xs-x1), (ys-y1));
			v5 = cross_product((x3-x2), (y3-y2), (xs-x2), (ys-y2));
			v6 = cross_product((x1-x3), (y1-y3), (xs-x3), (ys-y3));
		
			if (((v1 > 0) && (v2 > 0) && (v3 > 0) &&
				((v4 < 0) || (v5 < 0) || (v6 < 0))) ||
				((v4 > 0) && (v5 > 0) && (v6 > 0) &&
				((v1 < 0) || (v2 < 0) || (v3 < 0)))
				)
			{
				cout << "OK" << endl;
			}
			else
			{
				cout << "NG" << endl;
			}
		}
	}
	
	return 0;
}