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

int sign(int n){
	if(n < 0) return -1;
	if(n > 0) return 1;
	return 0;
}

float angle(int ax, int ay, int bx, int by, int cx, int cy){
    //angle between ab and ac
    float ab = atan2(by-ay,bx-ax);
    float ac = atan2(cy-ay,cx-ax);
    if(ab < 0)ab += 2*M_PI;
    if(ac < 0)ac += 2*M_PI;
    float ang = ac - ab;
    return (fabs(ang) < M_PI ? ang : -sign(ang) * 2 * M_PI + ang) * 180 / M_PI;
}

int isPointInTriangle(vector< int > &x, vector< int > &y, int px, int py){
	int n = x.size();
	double sum = 0;
	
	for(int i = 0; i < n; ++i){
		sum += angle(px, py, x[i], y[i], x[(i+1)%n], y[(i+1)%n]);
	}
	
	return (sum > 350 ? 1 : -1) ;
}

int main(){
	int n;
	int xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
	vector< int > x(3, 0);
	vector< int > y(3, 0);
	
	cin >> n;
	
	for(int i = 0; i < n; ++i){
		cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
		
		x[0] = xp1;
		x[1] = xp2;
		x[2] = xp3;
		
		y[0] = yp1;
		y[1] = yp2;
		y[2] = yp3;
		
		cout << (isPointInTriangle(x, y, xk, yk) * isPointInTriangle(x, y, xs, ys) < 0 ? "OK" : "NG") << endl;
	}
	return 0;
}