#include <iostream>
#include <cmath>
using namespace std;

struct Vec2d{
  double x,y;
};

double cross(Vec2d &A, Vec2d &B){
  return A.x*B.y - A.y*B.x;
}

int main(void){
	int n;cin>>n;
  while(n--){
  	double x1,y1,x2,y2,x3,y3,xk,yk,xs,ys;
  	cin>>x1>>y1>>x2>>y2>>x3>>y3>>xk>>yk>>xs>>ys;
    Vec2d AB,BC,CA,AK,BK,CK,AS,BS,CS;
    AB.x = x2-x1; AB.y = y2-y1;
    BC.x = x3-x2; BC.y = y3-y2;
    CA.x = x1-x3; CA.y = y1-y3;
    AK.x = xk-x1; AK.y = yk-y1;
    BK.x = xk-x2; BK.y = yk-y2;
    CK.x = xk-x3; CK.y = yk-y3;
    AS.x = xs-x1; AS.y = ys-y1;
    BS.x = xs-x2; BS.y = ys-y2;
    CS.x = xs-x3; CS.y = ys-y3;
    bool k=true,s=true;
    if(cross(AB,AK)>0.0 && cross(BC,BK)>0.0 && cross(CA,CK)>0.0)
    k=false;
    else if(cross(AB,AK)<0.0 && cross(BC,BK)<0.0 && cross(CA,CK)<0.0)
    k=false;
    else ;
    if(cross(AB,AS)>0.0 && cross(BC,BS)>0.0 && cross(CA,CS)>0.0)
    s=false;
    else if(cross(AB,AS)<0.0 && cross(BC,BS)<0.0 && cross(CA,CS)<0.0)
    s=false;
    else ;
    
    if(s!=k) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
    
  }
  return 0;
}