#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
 
using namespace std;
 
double EPS = 1e-10;
 
double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}
 
struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}
 
  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }
 
  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }
 
  point operator * (double d){
    return point(x*d,y*d);
  }
};
 
struct segment{
  point a,b;
};
 
double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}
 
double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}
 
int is_intersected_ls(point a1, point a2, point b1, point b2) {
  return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
         ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

 double vec_abs(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}

int ccw(point p0, point p1, point p2){
  point a = p1 - p0;
  point b = p2 - p0;
  if(cross(a,b)>EPS)return +1;
  if(cross(a,b)<EPS)return -1;
  if(dot(a,b)<-EPS)return +2;
  if(a.x*a.x+a.y*a.y<b.x*b.x+b.y*b.y)return -2;
  return 0;
}

int is_point_on_line(point a, point b, point c) {
  return (vec_abs(a-c) + vec_abs(c-b) < vec_abs(a-b) + EPS);
}

int inside(point p, point* ps, int n){
  segment t;
  t.a=t.b=p;
  t.b.x=DBL_MAX;

  double ymx=-DBL_MAX,ymn=DBL_MAX;
  for(int i=0;i<n;i++){
    ymx=max(ymx,ps[i].y);
    ymn=min(ymn,ps[i].y);
  }
  if(t.a.y<=ymn||t.a.y>=ymx)return 0;

  double xmx=-DBL_MAX,xmn=DBL_MAX;
  for(int i=0;i<n;i++){
    xmx=max(xmx,ps[i].x);
    xmn=min(xmn,ps[i].x);
  }
  if(t.a.x<=xmn||t.a.x>=xmx)return 0;

  int cnt=0;
  for(int i=0;i<n;i++){
    if(is_intersected_ls(ps[i],ps[i+1],t.a,t.b))cnt++;
  }
  return cnt%2;
}

int main(void){
  int n;
  point p[5],k,s;
 
  cin >> n;
  while(n--){

    for(int i=0;i<3;i++)
      cin >> p[i].x >> p[i].y;
     
    cin >> k.x >> k.y >> s.x >> s.y;
 
    if(inside(k,p,3)!=inside(s,p,3))cout << "OK" << endl;
    else cout << "NG" << endl;
     
  }
 
  return 0;
}