#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int range(double p,double q,double r){
  return (q<r?q:r)<p&&p<(q<r?r:q);
}
int rangea(double p,double q,double r){
  if(q*r<0&&fabs(q)+fabs(r)>M_PI){
    p+=2*M_PI*(p<0);
    q+=2*M_PI*(q<0);
    r+=2*M_PI*(r<0);
  }
  return range(p,q,r);
}
int pit(int x0,int y0,int x1,int y1,int x2,int y2,int xp,int yp){
  if(rangea(atan2(y0-yp,x0-xp),atan2(y0-y1,x0-x1),atan2(y0-y2,x0-x2)))
    if(rangea(atan2(y1-yp,x1-xp),atan2(y1-y0,x1-x0),atan2(y1-y2,x1-x2)))
      return 1;
  return 0;
}
int main(){
  int i;
  int n,x0,x1,x2,y0,y1,y2,xp,yp,xq,yq;
  vector<int> b;
  cin>>n;
  b.reserve(n);
  for(i=0;i<n;i++){
    cin>>x0>>y0>>x1>>y1>>x2>>y2>>xp>>yp>>xq>>yq;
    if(pit(x0,y0,x1,y1,x2,y2,xp,yp)^pit(x0,y0,x1,y1,x2,y2,xq,yq))
      b[i]=1;
    else
      b[i]=0;
  }
  for(i=0;i<n;i++){
    if(b[i])
      cout<<"OK"<<endl;
    else
      cout<<"NG"<<endl;
  }
  return 0;
}