#include<vector>
#include<complex>
#include<cassert>
#include<iostream>
#include<algorithm>
using namespace std;

const double eps = 1e-8;
const double inf = 1e12;

typedef complex<double> P; //Point

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

struct L {  //Line
  P s,t;
L(const P a,const P b) : s(a), t(b) {;}
};

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

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

int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if( cross(b, c) > 0 ) return +1; // counter clockwise
  if( cross(b, c) < 0 ) return -1; // clockwise
  if( dot(b, c) < 0 ) return +2;   // c--a--b on line
  if( norm(b) < norm(c) ) return -2; // a--b--c on line
  return 0;
}

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

int main() {
    int n,x,y;
    cin>>n;
    while(n--) {
        P tri[3];
        for(int i=0; i<3; ++i) {
            cin>>x>>y;
            tri[i] = P(x,y);
        }
        cin>>x>>y;
        P f(x,y);
        cin>>x>>y;
        P m(x,y);
        L fm(f,m);
        vector<L> tril;
        for(int i=0; i<3; ++i) tril.push_back(L(tri[i],tri[(i+1)%3]));

        int cc = 0;
        for(int i=0; i<3; ++i)
            if(intersectSS(fm, tril[i])) cc++;

        if(cc%2) cout<<"OK"<<endl;
        else cout<<"NG"<<endl;
    }
}