// 0143
#include <iostream>
using namespace std;

bool cross_p(int x1, int y1, int x2, int y2, int xp, int yp){
	if((x2-x1)*(yp-y1) < (y2-y1)*(xp-x1))
		return true;
	else
		return false;
}

int main(){

	int n;
	cin>>n;

	for(int i=0;i<n;i++){
		int x1, y1, x2, y2, x3, y3, xk, yk, xs, ys;
		bool altair, vega;

		cin>>x1>>y1>>x2>>y2>>x3>>y3>>xk>>yk>>xs>>ys;

		if((cross_p(x1, y1, x2, y2, xk, yk) == cross_p(x2, y2, x3, y3, xk, yk)) && (cross_p(x2, y2, x3, y3, xk, yk) == cross_p(x3, y3, x1, y1, xk, yk)))
			altair = true;
		else
			altair = false;

		if((cross_p(x1, y1, x2, y2, xs, ys) == cross_p(x2, y2, x3, y3, xs, ys)) && (cross_p(x2, y2, x3, y3, xs, ys) == cross_p(x3, y3, x1, y1, xs, ys)))
			vega = true;
		else
			vega = false;

		if(altair != vega)
			cout<<"OK"<<endl;
		else
			cout<<"NG"<<endl;
	}

	return 0;
}