#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct P{
	double x;
	double y;
};

int ccw(P p0, P p1, P p2)
{
	double dx1 = p1.x-p0.x;
	double dy1 = p1.y-p0.y;
	double dx2 = p2.x-p0.x;
	double dy2 = p2.y-p0.y;
	
	if(dx1*dy2 > dy1*dx2){
		return 1;
	} 
	if(dx1*dy2 < dy1*dx2){
		return -1;
	}
	if((dx1*dx2 < 0) || (dy1*dy2 < 0)){
		return -1;
	}
	if((dx1*dx1+dy1*dy1)<(dx2*dx2+dy2*dy2)){
		return 1;
	}
	
	return 0;
}

namespace std {
  bool operator < (const P& a, const P& b) {
    return a.x != b.x ? a.x < b.x : a.y < b.y;
  }
}

vector<P> convex_hull(vector<P> vec)
{
	int n = vec.size(), k = 0;
	sort(vec.begin(), vec.end());
	vector<P> ch(2*n);
	
	for(int i = 0; i < n; ch[k++] = vec[i++]){
		while(k >= 2 && ccw(ch[k-2], ch[k-1], vec[i]) <= 0){
			k--;
		}
	}
	
	for(int i = n-2, t = k+1; i >= 0; ch[k++] = vec[i--]){
		while(k >= t && ccw(ch[k-2], ch[k-1], vec[i]) <= 0){
			k--;
		}
	}
	
	ch.resize(k-1);
	
	return ch;
}

bool check(vector<P> vec, P p)
{
	bool f = false;
	
	for(int i = 0; i < vec.size(); i++){
		if(p.x == vec[i].x && p.y == vec[i].y){
			f = true;
			break;
		}
	}
	
	return f;
}


int main()
{
	int n;
	bool f;
	P pr[3], s, t;
	
	while(cin>>n && n){
		while(n--){
			cin >> pr[0].x >> pr[0].y >> pr[1].x >> pr[1].y >> pr[2].x >> pr[2].y >> s.x >> s.y >> t.x >> t.y;
			f = true;
			vector<P> vec;
			for(int i = 0; i < 3; i++){
				vec.push_back(pr[i]);
			}
			vec.push_back(t);
			vec = convex_hull(vec);
			if(vec.size() == 4){
				cout << "NG" << endl;
				continue;
			}
			if(check(vec, t)){
				cout << "NG" << endl;
				continue;
			}
			vec.clear();
			for(int i = 0; i < 3; i++){
				vec.push_back(pr[i]);
			}
			vec.push_back(s);
			vec = convex_hull(vec);
			if(vec.size() == 4){
				cout << "OK" << endl;
			} else {
				if(check(vec, s)){
					cout << "OK" << endl;
				} else {
					cout << "NG" << endl;
				}
			}
		}
	}
	
	return 0;
}