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

typedef double D;
const D EPS = 1e-8;

struct P {
  D x, y;
  P() { }
  P(D x_, D y_) : x(x_), y(y_) { }
};

P operator +(P a, P b) { return P(a.x + b.x, a.y + b.y); }
P operator -(P a, P b) { return P(a.x - b.x, a.y - b.y); }
P operator *(P a, D b) { return P(a.x * b, a.y * b); }
P operator /(P a, D b) { return P(a.x / b, a.y / b); }
P vec(P from, P to) { return to - from; }
D inp(P a, P b) { return a.x*b.x + a.y*b.y; }
D outp(P a, P b) { return a.x*b.y - a.y*b.x; }
D norm(P p) { return inp(p, p); }

int sig(D a, D b) {
  if(a < b - EPS) return -1;
  if(a > b + EPS) return +1;
  return 0;
}

int ccw(P a, P b, P c) { // 重なっている点があるとうまく動かないと思われる
  b = vec(a, b); c = vec(a, c);

  // a - b - c が折れ曲がるとき
  if(sig(outp(b, c),0.0) > 0) return +1; // 反時計回り
  if(sig(outp(b, c),0.0) < 0) return -1; // 時計回り

  // a - b - c が直線上に並ぶとき
  // sigを使わない実装が主流っぽい？
  if(sig(inp(b, c),0.0) < 0)   return +2; // c - a - b
  if(sig(norm(b),norm(c)) < 0) return -2; // a - b - c
  return 0;                               // a - c - b
}

// ON = 0, IN = 1, OUT = -1
int containsGP(vector<P> g, P p) {
  int side = -1;
  for(int i = 0; i < (int)g.size(); i++) {
    if(ccw(g[i], g[(i+1)%g.size()], p) == 0) return 0;
    P a = vec(p, g[i]);
    P b = vec(p, g[(i+1)%g.size()]);
    if(a.y > b.y) swap(a, b);
    if(sig(a.y, 0.0) <= 0 && sig(b.y, 0.0) > 0 && sig(outp(a, b), 0.0) > 0) side *= -1;
  }
  return side;
}

int main() {
  int N; cin >> N;
  while(N--) {
    vector<P> tri(3);
    for(int i = 0; i < 3; ++i) {
      cin >> tri[i].x >> tri[i].y;
    }
    P k, s;
    cin >> k.x >> k.y;
    cin >> s.x >> s.y;
    int side = containsGP(tri, k);
    side *= containsGP(tri, s);
    cout << (side == -1 ? "OK" : "NG") << endl;
  }
}