#include<vector>
#include<complex>
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

typedef vector<P> G;

struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

enum { OUT, ON, IN };
int contains(const G& g, const P& p) {
  bool in = false;
  for (int i = 0; i < g.size(); ++i) {
  	P a,b;
    a = curr(g,i) - p, b = next(g,i) - p;
    if (imag(a) > imag(b)) swap(a, b);
    if (imag(a) <= 0 && 0 < imag(b))
      if (cross(a, b) < 0) in = !in;
    if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;
  }
  return in ? IN : OUT;
}

int main(){
	int n; cin>>n;
	double x1,y1,x2,y2,x3,y3,xk,yk,xs,ys;
	while(n--){
		cin>>x1>>y1>>x2>>y2>>x3>>y3>>xk>>yk>>xs>>ys;
		P pk(xk,yk),ps(xs,ys),p1(x1,y1),p2(x2,y2),p3(x3,y3);
		G t;t.push_back(p1),t.push_back(p2),t.push_back(p3);
		bool f1=contains(t,pk),f2=contains(t,ps);
		cout<<(f1&&!f2||!f1&&f2?"OK":"NG")<<endl;
	}
	return 0;
}