#include <iostream>

using namespace std;

int xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;

bool side(int a, int b, int c, int d, int x, int y) {
  if (a == c)
    return x-a > 0;
  double p = (d - b) / (double)(c - a), q = b - p * a;
  return y > p * x + q;
}

bool inside_triangle(int x, int y) {
  return
    side(xp1, yp1, xp2, yp2, x, y) == side(xp1, yp1, xp2, yp2, xp3, yp3)
    && side(xp1, yp1, xp3, yp3, x, y) == side(xp1, yp1, xp3, yp3, xp2, yp2)
    && side(xp3, yp3, xp2, yp2, x, y) == side(xp3, yp3, xp2, yp2, xp1, yp1);
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
    if (inside_triangle(xk, yk) ^ inside_triangle(xs, ys))
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}