#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>


#define EPSILON 1e-9


class vector_t {
public:
  double x;
  double y;
  double z;

public:
  vector_t(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {};

public:
  double operator*(const vector_t& v) const {
    return x * v.x + y * v.y + z * v.z;
  };

  vector_t operator^(const vector_t& v) const {
    return vector_t(y * v.z - z * v.y,
                    z * v.x - x * v.z,
                    x * v.y - y * v.x);
  };

public:
  double length() const {
    return sqrt(*this * *this);
  };
};


class point_t {
public:
  double x;
  double y;
  double z;
  double w;

public:
  point_t(double x = 0, double y = 0, double z = 0, double w = 1) : x(x), y(y), z(z), w(w) {};
  
public:
  vector_t operator-(const point_t& p) const {
    return vector_t(x - p.x, y - p.y, z - p.z);
  };
};


class point_triangle_intersect : public std::unary_function<point_t, bool> {
public:
  point_triangle_intersect(const point_t& p1,
                           const point_t& p2,
                           const point_t& p3) :
    p1_(p1), p2_(p2), p3_(p3), s_(((p2 - p1) ^ (p3 - p1)).z)
  {
  };
 
public:
  bool operator()(const point_t& p) const {
    double u = ((p1_ - p3_) ^ (p - p3_)).z / s_;
    double v = ((p2_ - p1_) ^ (p - p1_)).z / s_;

    return (u >= 0 && v >= 0 && u + v <= 1.0 + EPSILON);
  };
 
private:
  point_t p1_;
  point_t p2_;
  point_t p3_;

  double s_;
};


int main(int argc, char** argv)
{
  int n;

  std::cin >> n;

  for (int i = 0; i < n; i ++) {
    point_t p1, p2, p3, k, s;

    std::cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
    std::cin >> k .x >> k .y >> s .x >> s .y;

    if (point_triangle_intersect(p1, p2, p3)(k) ^
        point_triangle_intersect(p1, p2, p3)(s)) {

      std::cout << "OK" << std::endl;
    }
    else {
      std::cout << "NG" << std::endl;
    }
  }

  return 0;
}