#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int pt(double px,double py,double qx,double qy,double rx,double ry,double sx,double sy){
  if(((rx-qx)*(py-qy)-(px-qx)*(ry-qy)<=0&&(sx-rx)*(py-ry)-(px-rx)*(sy-ry)<=0&&(qx-sx)*(py-sy)-(px-sx)*(qy-sy)<=0)||
     ((rx-qx)*(py-qy)-(px-qx)*(ry-qy)>=0&&(sx-rx)*(py-ry)-(px-rx)*(sy-ry)>=0&&(qx-sx)*(py-sy)-(px-sx)*(qy-sy)>=0))
    return 1;
  return 0;
}
int main(){
  int h,i;
  int n;
  cin>>n;
  for(h=0;h<n;h++){
    int x[5],y[5];
    for(i=0;i<5;i++)
      cin>>x[i]>>y[i];
    if(pt(x[3],y[3],x[0],y[0],x[1],y[1],x[2],y[2])^
       pt(x[4],y[4],x[0],y[0],x[1],y[1],x[2],y[2]))
      cout<<"OK"<<endl;
    else
      cout<<"NG"<<endl;
  }
  return 0;
}