#include <iostream>
#include <cmath>
#define EPS (1e-10)
using namespace std;

class Point{
public:
  int x, y;
};
class Segment{
public:
  Point p1, p2;
};

double norm(Point a){
  return a.x*a.x+a.y*a.y;
}

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 ccw(Point p0, Point p1, Point p2){
  Point a;
  a.x=p1.x-p0.x;
  a.y=p1.y-p0.y;
  Point b;
  b.x=p2.x-p0.x;
  b.y=p2.y-p0.y;
  if(cross(a, b) > EPS) return 1;
  if(cross(a, b) < -EPS) return -1;
  if(dot(a, b) < -EPS) return 2;
  if(norm(a) < norm(b)) return -2;
  return 0;
}

bool isIntersect(Point p1, Point p2, Point p3, Point p4){
  return ( ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
	   ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0 );
}

bool isIntersect(Segment s1, Segment s2){
  return isIntersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

main(){
  int n;
  while(cin >> n){
    for(int i=0;i<n;i++){
      int xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
      cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
      Point a, b, c, k, s;
      a.x=xp1;
      a.y=yp1;
      b.x=xp2;
      b.y=yp2;
      c.x=xp3;
      c.y=yp3;
      k.x=xk;
      k.y=yk;
      s.x=xs;
      s.y=ys;
      Segment ab, bc, ca, ks;
      ab.p1=b;
      ab.p2=a;
      bc.p1=c;
      bc.p2=b;
      ca.p1=a;
      ca.p2=c;
      ks.p1=s;
      ks.p2=k;
      int count=0;
      if(isIntersect(ks, ab)) count++;
      if(isIntersect(ks, bc)) count++;
      if(isIntersect(ks, ca)) count++;
      if(count==1) cout << "OK" << endl;
      else cout << "NG" << endl;
    }
  }
  return 0;
}