#include <bits/stdc++.h>

using namespace std;

class Point {
public:
	int x, y;
};

Point PointData[5];


int isExistTriangle(const Point& p) {

	int r1 = (PointData[1].x - PointData[0].x) * (p.y - PointData[0].y) - (p.x - PointData[0].x) * (PointData[1].y - PointData[0].y);
	int r2 = (PointData[2].x - PointData[1].x) * (p.y - PointData[1].y) - (p.x - PointData[1].x) * (PointData[2].y - PointData[1].y);
	int r3 = (PointData[0].x - PointData[2].x) * (p.y - PointData[2].y) - (p.x - PointData[2].x) * (PointData[0].y - PointData[2].y);

	if (r1 > 0 && r2 > 0 && r3 > 0) {
		return 1;
	}
	if (r1 < 0 && r2 < 0 && r3 < 0) {
		return 1;
	}
	return -1;
}

int main(void) {
	int n, flag1, flag2;

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 5; j++) {
			cin >> PointData[j].x >> PointData[j].y;
		}
		
		flag1 = isExistTriangle(PointData[3]);
		flag2 = isExistTriangle(PointData[4]);
		//cout << flag1 << ends << flag2 << endl;
		if (flag1*flag2 == 1) {
			cout << "NG" << endl;
		}
		else {
			cout << "OK" << endl;
		}
	}

	return 0;
}
