#include "bits/stdc++.h"
using namespace std;

typedef long long lli;
typedef pair<int,int> pii;
#define rep(i,n) for(lli i=0;i<(lli)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

#define F first
#define S second

#define EPS 1e-9

double f(pii a,pii b,pii c){
    pii p1,p2;
    p1=pii( a.F-b.F , a.S-b.S );
    p2=pii( a.F-c.F , a.S-c.S );
    
    return p1.F*p2.S-p1.S*p2.F;
}


int main(){
    int n;
    cin>>n;
    rep(hoge,n){
        pii p1,p2,p3,k,s;
        cin>>p1.F>>p1.S>>p2.F>>p2.S>>p3.F>>p3.S>>k.F>>k.S>>s.F>>s.S;
        
        
        double a=f(p1,p2,k);
        double b=f(p2,p3,k);
        double c=f(p3,p1,k);
        
        bool x;
        
        if( (a>=0&&b>=0&&c>=0) || (a<0+EPS&&b<0+EPS&&c<0+EPS) )x=true;
        else x=false;

    
        a=f(p1,p2,s);
        b=f(p2,p3,s);
        c=f(p3,p1,s);
        
        bool y;
        
        if( (a>=0&&b>=0&&c>=0) || (a<0+EPS&&b<0+EPS&&c<0+EPS) )y=true;
        else y=false;
        if(x==y)cout<<"NG"<<endl;
        else cout<<"OK"<<endl;
    }

}