#include <iostream>

using namespace std;

class Point{
public:
	int x;
	int y;

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

	int dot(Point other){
		int d =  (*this).x*other.x + (*this).y*other.y;
		return (*this).x*other.x + (*this).y*other.y;
	}

	int cross(Point other){
		return (*this).x*other.y - (*this).y*other.x;
	}

	int distsq(Point other){
		//int dx = (*this).x-other.x;
		//int dy = (*this).y-other.y;
		return ((*this).x-other.x)*((*this).x-other.x)+((*this).y-other.y)*((*this).y-other.y);
	}

	Point operator+(Point other){
		Point p;
		p.x = (*this).x + other.x;
		p.y = (*this).y + other.y;
		return p;
	}

	Point operator+=(Point other){
		(*this) = (*this)+other;
		return (*this);
	}

	Point operator-(Point other){
		Point p;
		p.x = (*this).x - other.x;
		p.y = (*this).y - other.y;
		return p;
	}

	Point operator-=(Point other){
		(*this) = (*this)-other;
		return (*this);
	}

	// cout 出力用
   friend ostream& operator << (ostream& os, const Point& p){
	   os << '(' << p.x << ", " << p.y << ')';
	   return os;
   }

};

class Triangle{
public:
	Point vertex[3];

	Triangle(Point a = Point(0,0), Point b = Point(0,0), Point c = Point(0,0)){
		vertex[0] = a;
		vertex[1] = b;
		vertex[2] = c;
	}

	bool isInclude(Point p){
		// 三角形ABCと点Pに関し、3つの外積 AB×AP, BC×BP, CA×CPの符号が同じであれば三角形の中
		int cnt = 0;
		for(int i = 0; i < 3; i++){
			Point vs = vertex[(i+1)%3] - vertex[i]; // 辺のベクトル
			Point vp = p - vertex[i];				// 各辺の始点→点Pのベクトル
			cnt += (vs.cross(vp) > 0)?1:-1;
		}
		cnt = (cnt>0)?cnt:-cnt;
		if(cnt == 3) return true;
		else return false;
	}
};

int main(){
	int n;
	cin >> n;

	while(n--){
		Triangle wall;
		Point a, b;
		for(int i = 0; i < 3; i++){
			cin >> wall.vertex[i].x >> wall.vertex[i].y;
		}
		cin >> a.x >> a.y >> b.x >> b.y;

		if(wall.isInclude(a)^wall.isInclude(b)) cout << "OK" << endl;
		else cout << "NG" << endl;
	}

	return 0;

}