#include <iostream>
#include <cmath>

using namespace std;

struct Point {
	double x, y;
	Point(double x=0, double y=0) : x(x), y(y) {}
	Point operator-(const Point &o) const {
		return Point(x-o.x, y-o.y);
	}
};

double cross(Point &a, Point &b) {
	return (a.x * b.y - b.x * a.y);
}

bool in(Point &a, Point &b, Point &c, Point &p) {
	Point ab = b-a;
	Point bc = c-b;
	Point ca = a-c;
	Point ap = p-a;
	Point bp = p-b;
	Point cp = p-c;
	double cross_a = cross(ab, ap);
	double cross_b = cross(bc, bp);
	double cross_c = cross(ca, cp);
	return (cross_a / abs(cross_a) == cross_b / abs(cross_b) &&
			cross_b / abs(cross_b) == cross_c / abs(cross_c));
}



int main() {
	int n; cin >> n;
	while (n--) {
		Point v[3], altair, vega;
		for (int i = 0; i < 3; i++) cin >> v[i].x >> v[i].y;
		cin >> altair.x >> altair.y >> vega.x >> vega.y;

		bool altair_in, vega_in;
		altair_in = in(v[0], v[1], v[2], altair);
		vega_in = in(v[0], v[1], v[2], vega);

		if (altair_in ^ vega_in) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
	return 0;
}



	