#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
struct Point { long double px, py; };
Point Minus(Point a, Point b) { Point O; O.px = a.px - b.px; O.py = a.py - b.py; return O; }
long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; }
long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; }
int contain(vector<Point> v, Point p) {
	bool in = false;
	for (int i = 0; i < v.size(); ++i) {
		Point a = Minus(v[i], p), b = Minus(v[(i + 1) % v.size()], p);
		if (a.py > b.py) swap(a, b);
		if (a.py <= 0 && 0 < b.py)
			if (crs(a, b) < 0) in = !in;
		if (crs(a, b) == 0 && dot(a, b) <= 0) return 1;
	}
	return in ? 2 : 0;
}
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		Point p1, p2, p3, p4, p5;
		cin >> p1.px >> p1.py >> p2.px >> p2.py >> p3.px >> p3.py >> p4.px >> p4.py >> p5.px >> p5.py;
		vector<Point>C = { p1,p2,p3 };
		bool G1 = contain(C, p4), G2 = contain(C, p5);
		if (G1 ^ G2 == true)cout << "OK" << endl;
		else { cout << "NG" << endl; }
	}
	return 0;
}