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

typedef double D;
D EPS = 1e-10;

struct Point {
	D x, y;
	Point() {}
	Point (D _x, D _y) : x(_x), y(_y) {}
};
typedef Point Vector;	// typedef テ」ツ?ァテ」ツδ凖」ツつッテ」ツδ暗」ツδォテ」ツ?ォテ・ツッツセテ・ツソツ?

// operator
Point operator + (const Point& a, const Point& b) { return Point(a.x+b.x, a.y+b.y); }
Point operator - (const Point& a, const Point& b) { return Point(a.x-b.x, a.y-b.y); }
Point operator * (const Point& a, const Point& b) { return Point(a.x*b.x, a.y*b.y); }
Point operator / (const Point& a, const Point& b) { return Point(a.x/b.x, a.y/b.y); }
bool operator < (const Point& a, const Point& b) { return a.x != b.x ? a.x < b.x : a.y < b.y; }
bool operator > (const Point& a, const Point& b) { return b.x != a.x ? b.x < a.x : b.y < a.y; }
bool operator == (const Point& a, const Point& b) { return fabs(a.x-b.x)<EPS && fabs(a.y-b.y)<EPS; }

// テ・ツ淞コテヲツ慊ャテァツ堋?」ツ?ェテゥツ鳴「テヲツ閉ー
D norm(const Point& a) { return sqrt(a.x*a.x + a.y*a.y); }
D dot(const Vector& a, const Vector& b) { return a.x*b.x + a.y*b.y; }	// テ・ツ??ァツゥツ?
D cross(const Vector& a, const Vector& b) { return a.x*b.y - a.y*b.x; }	// テ・ツ、ツ姪ァツゥツ?
D dist(const Point& a, const Point& b) { return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)); } // ティツキツ敕ゥツ崢「
bool isVertical(const Vector& a, const Vector& b) { return fabs(dot(a,b))<EPS; }	// テ・ツ楪づァツ崢エテ・ツ按、テ・ツョツ?
bool isParrallel(const Vector& a, const Vector& b) { return fabs(cross(a,b))<EPS; } // テ・ツケツウティツ。ツ古・ツ按、テ・ツョツ?

struct Line {
	Point s, e;
	Line (Point _s, Point _e) {
		s = _s; e = _e;
	}
};

bool PointOnLine(const Point& p, const Line& l) {
	int minx = min(l.s.x, l.e.x), maxx = max(l.s.x, l.e.x);
	int miny = min(l.s.y, l.e.y), maxy = max(l.s.y, l.e.y);
	if ( !(minx <= p.x && p.x <= maxx && miny <= p.y && p.y <= maxy) ) return false;
	Vector v1 = p - l.s, v2 = l.e - l.s;
	return isParrallel(v1, v2);
}

enum { IN, ON, OUT };
int PointInTri(const vector<Point>& tri, const Point& p) {
    int cnt = 0;
    for (int i=1; i<4; i++) {
        Point p0 = tri[i-1], p1 = tri[i%3];
        bool flag0x = (p.x <= p0.x), flag0y = (p.y <= p0.y);
        bool flag1x = (p.x <= p1.x), flag1y = (p.y <= p1.y);
        
        Line p0top1(p0, p1);
        if (PointOnLine(p, p0top1)) return ON;
         
        if (flag0y != flag1y) {
            if ( flag1x && flag0x) {
                cnt += flag0y ? -1 : 1;
            } else if (p.x <= ( p0.x+(p1.x-p0.x)*(p.y-p0.y)/(p1.y-p0.y) ) ) {
                cnt += flag0y ? -1 : 1;
            }
        }
    }
    return cnt!=0 ? IN : OUT;
}
 
int main() {
    int n; cin >> n;
     
    vector<Point> tri(3);
    for (int i=0; i<n; i++) {
        cin >> tri[0].x >> tri[0].y >> tri[1].x >> tri[1].y >> tri[2].x >> tri[2].y;
        Point p1; cin >> p1.x >> p1.y;
        Point p2; cin >> p2.x >> p2.y;
        bool flag1 = (PointInTri(tri, p1) == IN), flag2 = (PointInTri(tri, p2) == IN);
        if ( flag1 != flag2 ) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
     
    return 0;
}