#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n,loc1,loc2;
	double x1,x2,x3,y1,y2,y3,xp,yp,xq,yq;
	double calc1,calc2,calc3,calc4,calc5,calc6;


	scanf("%d",&n);

	for(int i = 0; i < n; i++){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp,&xq,&yq);

		calc1 = (x2-x1)*(yp-y1)-(y2-y1)*(xp-x1);
		calc2 = (x3-x2)*(yp-y2)-(y3-y2)*(xp-x2);
		calc3 = (x1-x3)*(yp-y3)-(y1-y3)*(xp-x3);

		calc4 = (x2-x1)*(yq-y1)-(y2-y1)*(xq-x1);
		calc5 = (x3-x2)*(yq-y2)-(y3-y2)*(xq-x2);
		calc6 = (x1-x3)*(yq-y3)-(y1-y3)*(xq-x3);

		if((calc1>0&&calc2>0&&calc3>0) || (calc1<0&&calc2<0&&calc3<0)){
			loc1 = 0;
		}else{
			loc1 = 1;
		}

		if((calc4>0&&calc5>0&&calc6>0) || (calc4<0&&calc5<0&&calc6<0)){
			loc2 = 0;
		}else{
			loc2 = 1;
		}

		if(loc1 == loc2)printf("NG\n");
		else{
			printf("OK\n");
		}

	}

    return 0;
}