#include <iostream>
using namespace std;

struct point{
	double x;
	double y;
};

int ccw(point p0, point p1, point p2){
	double dx1 = p1.x - p0.x, dy1 = p1.y - p0.y;
	double dx2 = p2.x - p0.x, dy2 = p2.y - p0.y;
	if(dx1 * dy2 > dx2 * dy1){
		return 1;
	}else if(dx1 * dy2 > dx2 * dy1){
		return -1;
	}
	return 0;
}

bool in_t(point p0, point p1, point p2, point p3){
	if((ccw(p0, p1, p2) == -ccw(p0, p1, p3)
		&& (ccw(p0, p2, p1) == -ccw(p0, p2, p3))))
		return true;
	else return false;
}


int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		point p1, p2, p3;
		point pk, ps;
		cin >> p1.x >> p1.y >> p2.x >> p2.y
			>> p3.x >> p3.y >> pk.x >> pk.y >>  ps.x >> ps.y;
		if((in_t(pk, p1, p2, p3) && !in_t(ps, p1, p2, p3)) ||
			(!in_t(pk, p1, p2, p3) && in_t(ps, p1, p2, p3)))
			cout << "OK" << endl;
		else cout << "NG" << endl;
	}
	return 0;
}