#include <iostream>
#include <vector>
#include <complex>
using namespace std;
const double INF = 1e12;
typedef complex<double> P,point;
typedef vector<P> G,polygon;
namespace std {bool operator < (const P& a, const P& b) {return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);}}
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}
struct L : public vector<P> {L(const P &a, const P &b) {push_back(a); push_back(b);}};
int ccw(P a, P b, P c) {b -= a; c -= a;if (cross(b, c) > 0)   return +1;if (cross(b, c) < 0)   return -1;if (dot(b, c) < 0) return +2;if (norm(b) < norm(c)) return -2;return 0;}
bool intersectSS(const L &s, const L &t) {return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 && ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;}

// Where is Point in Polygon? //
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
enum { OUT, ON, IN };
int contains(const polygon& P, const point& p) {bool in = false;for (int i = 0; i < P.size(); ++i) {point a = curr(P,i) - p, b = next(P,i) - p;if (imag(a) > imag(b)) swap(a, b);if (imag(a) <= 0 && 0 < imag(b))if (cross(a, b) < 0) in = !in;if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;}return in ? IN : OUT;}

#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;cin >> n;
	while(n--){
		P data[5];
		G v;
		rep(i,3){P c; cin >> c.real() >> c.imag(); v.push_back(c);}
		P a,b;
		cin >> a.real() >> a.imag() >> b.real() >> b.imag();
		cout << ( (!!contains(v,a)) ^ (!!contains(v,b)) ?"OK":"NG") << endl;
	}
}