#include <bits/stdc++.h>

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;
typedef complex<double> P;
const double EPS = 1e-8;
const double INF = 1e12;
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); }
typedef vector<P> G;

#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
enum { OUT, ON, IN };

int contains(const G& x, const P& y){
  bool in_ = false;
  rep(i, x.size()){
    P a = curr(x, i) - y, b = next(x, i) - y;
    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;
}

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }


int main()
{
  rep(i, in()){
    G area;
    rep(j, 3){
      int x, y;
      x = in();
      y = in();
      area.push_back(P(x, y));
    }
    int x, y;
    x = in();
    y = in();
    P k(x, y);
    x = in();
    y = in();
    P s(x, y);
    if (contains(area, k) != contains(area, s)){
      puts("OK");
    }
    else {
      puts("NG");
    }
  }
  return 0;
}