#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;

double EPS = 1e-10;



// ??????????????????????¶????????????????
double add(double a,double b){
	if(abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
	return a + b;
}

// ????¬?????????????????§???????
struct P {
	double x,y;
	P(){}
	P(double x,double y) : x(x), y(y){
	}
	P operator + (P p){
		return P(add(x, p.x), add(y, p.y));
	}
	P operator - (P p){
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator * (double d){
		return P(x * d, y * d);
	}
	double dot(P p){	// ??????
		return add(x * p.x, y * p.y);
	}
	double det(P p){	// ??????
		return add(x * p.y, -y * p.x);
	}
};

int main(){
	int n;
	vector<P> p(5);
	cin>>n;
	while(n--){
		rep(i, 5) cin>>p[i].x>>p[i].y;
		bool f1 =true, f2 = true;
		for(int i = 0; i < 3; i++){
			if((p[3]-p[i]).det(p[(i+1)%3]-p[i])>0
				!=(p[3]-p[(i+1)%3]).det(p[(i+2)%3]-p[(i+1)%3])>0){
				f1 = false;
				break;
			}
		}
		for(int i = 0; i < 3; i++){
			if(((p[4]-p[i]).det(p[(i+1)%3]-p[i])>0)
				!=((p[4]-p[(i+1)%3]).det(p[(i+2)%3]-p[(i+1)%3])>0)){
				f2 = false;
				break;
			}
		}
		cout<<(f1^f2?"OK":"NG")<<endl;
	}
}