#include <bits/stdc++.h>

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);
}

typedef vector<P> G;

#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
int contains(const G& g, const P& p) {
  bool in = false;
  for (int i = 0; i < g.size(); ++i) {
      P 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 true;
    }
  return in ? true : false;
}

int main(){
    int n;
    cin >> n;
    for(int q=0; q < n; q++){
        G g(3); P a, b;
        double xp1,yp1,xp2,yp2,xp3,yp3, xk, yk, xs, ys;
        cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
        g[0] = P(xp1, yp1); g[1] = P(xp2, yp2); g[2] = P(xp3, yp3);
        a = P(xk, yk); b = P(xs, ys);
        cout << (contains(g, a) xor contains(g, b) ? "OK" : "NG") << endl;
    }
}