#include <iostream>
#include <stdio.h>

using namespace std;

int hantei(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy) {
	double y,m,n,d;
	if ((bx-ax==0 && dx-cx==0) || (by-ay==0 && dy-cy==0)) return 0; 
	if (dx-cx!=0) m=(dy-cy)/(dx-cx);
	if (bx-ax!=0) n=(by-ay)/(bx-ax);
	if (ax==bx) {
        if (cy==dy && ((cy>ay && cy<by) || (cy>by && cy<ay)) && ((cx<ax && dx>ax) || (dx<ax && cx>ax))) return 1;
        y=cy+m*(ax-cx);
		if (((y>cy && y<dy) || (y>dy && y<cy)) && ((y>ay && y<by) || (y>by && y<ay))) return 1;
		return 0;} 
	if (cx==dx) {
		y=ay+n*(cx-ax);
		if (((y>cy && y<dy) || (y>dy && y<cy)) && ((y>ay && y<by) || (y>by && y<ay))) return 1;
		return 0;}
	d=(ay-cy+m*cx-n*ax)/(m-n);
	if (((d>cx && d<dx) || (d>dx && d<cx)) &&((d>ax && d<bx) || (d>bx && d<ax)))  return 1;
	return 0;
}

int main() {
	int n,f;
	double xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys;
	cin >> n;
	for (;n>0;n--) {
		cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
        f=hantei(xp1,yp1,xp2,yp2,xk,yk,xs,ys)+hantei(xp2,yp2,xp3,yp3,xk,yk,xs,ys)+hantei(xp1,yp1,xp3,yp3,xk,yk,xs,ys);
		if (f==1) cout << "OK"; else cout << "NG";
		cout << endl;
	}
return 0;
	}