#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>
#include <bitset>
#include <set>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
typedef long long int lint;

class Point {
public:
	int x;
	int y;

	Point() {
		x = y = 0;
	}
	Point(int x, int y) {
		this->x = x; this->y = y;
	}

	Point operator + (Point obj) {
		return Point(this->x + obj.x, this->y + obj.y);
	}
	Point operator - (Point obj) {
		return Point(this->x - obj.x, this->y - obj.y);
	}
	int operator * (Point obj) {
		return (this->x * obj.y - this->y * obj.x);
	}

	friend std::ostream& operator << (std::ostream& ostr, const Point& p) {
		std::cout << "{" << p.x << ", " << p.y << "}";
		return ostr;
	}
};

bool interior(Point p1, Point p2, Point p3, Point p) {
	Point v1, v2, v3, pp1, pp2, pp3;
	v1 = p2 - p1; v2 = p3 - p2; v3 = p1 - p3;
	pp1 = p - p1; pp2 = p - p2; pp3 = p - p3;
	int cp1, cp2, cp3;
	cp1 = v1 * pp1; cp2 = v2 * pp2; cp3 = v3 * pp3;
	if (cp1 < 0 && cp2 < 0 && cp3 < 0) return true;
	if (cp1 > 0 && cp2 > 0 && cp3 > 0) return true;
	return false;
}

void AOJ0143()
{
	Point p[3], k, s;
	REP(i, 3) {
		cin >> p[i].x >> p[i].y;
	}
	cin >> k.x >> k.y >> s.x >> s.y;

	if (interior(p[0], p[1], p[2], k) ^ interior(p[0], p[1], p[2], s)) {
		cout << "OK" << endl;
	}
	else cout << "NG" << endl;

	return;
}

int main()
{
	int n;
	cin >> n;
	REP(i, n) AOJ0143();

	return 0;
}