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


class Point {
public:
  double x, y;
  Point(double x=0, double y=0) : x(x), y(y) {}
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
};

typedef Point Vector;

double cross(Vector a, Vector b) { return a.x*b.y - a.y*b.x; }


Point p1, p2, p3, k, s;

bool isInTry(Point p) {
  double c1 = cross(p2 - p1, p - p1);
  double c2 = cross(p3 - p2, p - p2);
  double c3 = cross(p1 - p3, p - p3);
  return c1 * c2 > 0.0 && c2 * c3 > 0.0;
}

void solve() {
  bool f1 = isInTry(k);
  bool f2 = isInTry(s);
  if((!f1 || !f2) && (f1 || f2)) cout << "OK" << endl;
  else                           cout << "NG" << endl;
}

main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y
	>> k.x >> k.y >> s.x >> s.y;
    solve();
  }
}