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

double EPS = 1e-9; 

struct Point {
    double x, y;
};

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

double distPointLine(const Point& A, const Line& l) {
	double a = (l.s.y - l.e.y)/(l.s.x - l.e.x);
	double c = (-1)*a*l.s.x - l.s.y;
	return fabs(a * A.x + A.y + c)/sqrt(a*a + 1.0);
}

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 (distPointLine(p, p0top1) <= EPS) 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;
}