#include <bits/stdc++.h>

using namespace std;

const double eps = 1e-10;

struct P {
  double x, y;
  P(double x = 0.0, double y = 0.0): x(x), y(y) {}
};

bool inTri(P p[3], P a) {
  double dx[2], dy[2];
  double area_p, area_a = 0.0;

  for (int i = 0; i < 2; i++) {
    dx[i] = p[i].x - p[2].x;
    dy[i] = p[i].y - p[2].y;
  }

  area_p = abs(dx[0] * dy[1] - dx[1] * dy[0]) / 2.0;

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 2; j++) {
      dx[j] = p[(i + j) % 3].x - a.x;
      dy[j] = p[(i + j) % 3].y - a.y;
    }

    area_a += abs(dx[0] * dy[1] - dx[1] * dy[0]) / 2.0;
  }

  return area_a - area_p < eps;
}

int main(void) {
  int n;
  cin >> n;

  P pp[3], pk, ps;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> pp[j].x >> pp[j].y;
    }
    cin >> pk.x >> pk.y >> ps.x >> ps.y;

    bool in_k = inTri(pp, pk), in_s = inTri(pp, ps);
    if ((in_k && !in_s) || (!in_k && in_s)) {
      cout << "OK\n";
    } else {
      cout << "NG\n";
    }
  }

  return 0;
}
