#include <bits/stdc++.h>
using namespace std;
typedef double frac;
typedef complex<frac> Pt;
struct less_c{
    bool operator() (const Pt& a, const Pt& b){
	    return a.real()!=b.real() ? a.real()<b.real() : a.imag()<b.imag();
    }
};
frac cross(Pt a, Pt b){ //外積
    return a.real()*b.imag()-a.imag()*b.real();
}

bool in_convex(vector<Pt> p, Pt q){
    vector<Pt> pp=p;
    pp.push_back(q);
    
    int n=pp.size();
    sort(pp.begin(),pp.end(),less_c());
    vector<Pt> ch(2);
    for(int i=0; i<2; i++) ch[i]=pp[i];
    for(int i=2; i<n; i++){
        for(int j=ch.size()-1; j>0; j--){
            if(cross(pp[i]-ch[j],ch[j-1]-ch[j])<0){
                ch.erase(ch.begin()+j);
            }else{
                break;
            }
        }
        ch.push_back(pp[i]);
    }
    
    int half=ch.size()-1;
    ch.push_back(pp[n-2]);
    for(int i=n-3; i>=0; i--){
        for(int j=ch.size()-1; j>half; j--){
            if(cross(pp[i]-ch[j],ch[j-1]-ch[j])<0){
                ch.erase(ch.begin()+j);
            }else{
                break;
            }
        }
        ch.push_back(pp[i]);
    }
    ch.pop_back();

    sort(ch.begin(),ch.end(),less_c());
    sort(p.begin(),p.end(),less_c());
    return ch==p;
}

int main(){
	int n;  cin >> n;
    for(int i=0; i<n; i++){
        int x, y;
        vector<Pt> p(3);
        for(int j=0; j<3; j++){
            cin >> x >> y;
            p[j]={frac(x),frac(y)};
        }
        Pt k, s;
        cin >> x >> y;  k={frac(x),frac(y)};
        cin >> x >> y;  s={frac(x),frac(y)};
        
        cout << (in_convex(p,k)!=in_convex(p,s) ? "OK" : "NG") << endl; 
    }
}
