//47
#include<iostream>
#include<complex>

using namespace std;

typedef complex<double> P;

bool in(P x,P *a){
  bool sg[2]={};
  for(int i=0;i<3;i++){
    P e=a[(i+1)%3]-a[i];
    P d=x-a[i];
    sg[e.real()*d.imag()-e.imag()*d.real()<0]=true;
  }
  return sg[0]^sg[1];
}

int main(){
  int n;
  cin>>n;
  while(n--){
    P p[5];
    for(int i=0;i<5;i++){
      double x,y;
      cin>>x>>y;
      p[i]=P(x,y);
    }
    cout<<(in(p[3],p)^in(p[4],p)?"OK":"NG")<<endl;
  }
  return 0;
}
      