#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a) * b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
	return l.first + t * (l.first - l.second);
}

int ccw(xy_t a, xy_t b, xy_t 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 intersectSP(const line &l, const xy_t &p){
	return abs(l.first- p) + abs(l.second - p) - abs(l.first - l.second) < EPS;
}

bool intersectSS(const line &s, const line &t){
	return ccw(s.first, s.second, t.first) * ccw(s.first, s.second, t.second) <= 0 &&
		ccw(t.first, t.second, s.first) * ccw(t.first, t.second, s.second) <= 0;
}

double distanceSP(line s, xy_t p){
	const xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

int main(){
	int n;
	double xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
	line s, l[3];
	cin >> n;
	rep(t, n){
		cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
		l[0] = line(xy_t(xp1, yp1), xy_t(xp2, yp2));
		l[1] = line(xy_t(xp2, yp2), xy_t(xp3, yp3));
		l[2] = line(xy_t(xp3, yp3), xy_t(xp1, yp1));
		s = line(xy_t(xs, ys), xy_t(xk, yk));
		int cnt = 0;
		rep(i, 3) if(intersectSS(l[i], s)) cnt++;
		if(cnt % 2 == 0) cout << "NG" << endl;
		else cout << "OK" << endl;
	}
	return 0;
}