#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

struct Vector2D{
    double x;
    double y;
};
//???????????????(??????????????¨??????)
#define Vertex2D Vector2D

//?????????????????????(a-b)
Vector2D sub_vector( const Vector2D& a, const Vector2D& b )
{
    Vector2D ret;
    ret.x = a.x - b.x;
    ret.y = a.y - b.y;
    return ret;
}

// ????§???¢??¨?????????????????????(2D?????´???)
// ?????????    0:????§???¢????????´???????????????    1:????§???¢????????´???????????????
int hittest_point_polygon_2d( Vertex2D A, Vertex2D B, Vertex2D C, Vertex2D P ) {

    //??????????????¨??????????????????
    //ABC???????§???¢????????????????????§??????????????\...
    
    Vector2D AB = sub_vector(B, A);
    Vector2D BP = sub_vector(P, B);

    Vector2D BC = sub_vector(C, B);
    Vector2D CP = sub_vector(P, C);

    Vector2D CA = sub_vector(A, C);
    Vector2D AP = sub_vector(P, A);

    //??????    Z?????????????¨????????????°????????§???
    double c1 = AB.x * BP.y - AB.y * BP.x;
    double c2 = BC.x * CP.y - BC.y * CP.x;
    double c3 = CA.x * AP.y - CA.y * AP.x;

    if( ( c1 > 0 && c2 > 0 && c3 > 0 ) || ( c1 < 0 && c2 < 0 && c3 < 0 ) ) {
        //????§???¢????????´???????????????
        return 0;
    }

    //????§???¢????????´???????????????
    return 1;

}

int main(){
	
	Vertex2D A, B, C, P, Q;
	
	int n;
	
	cin >> n;
	
	for(int loop = 0; loop < n; loop++){
		cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y >> P.x >> P.y >> Q.x >> Q.y;
		if((hittest_point_polygon_2d(A, B, C, P) + hittest_point_polygon_2d(A, B, C, Q)) % 2 == 1){
			printf("OK\n");
		}else{
			printf("NG\n");
		}
	}
	
	return 0;
}