#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.h>
#include <set>


using namespace std;

//二次元の外積
//回転の方向
double gaiseki(double x1, double y1, double x2, double y2){
    return x1*y2-x2*y1;
}

bool inside_outside_of_triangle(double xpa, double ypa, double xpb, double ypb, double xpc, double ypc, double x, double y){
    double vab_x = xpa-xpb;
    double vab_y = ypa-ypb;
    double vbc_x = xpb-xpc;
    double vbc_y = ypb-ypc;
    double vca_x = xpc-xpa;
    double vca_y = ypc-ypa;
    double vap_x = xpa-x;
    double vap_y = ypa-y;
    double vbp_x = xpb-x;
    double vbp_y = ypb-y;
    double vcp_x = xpc-x;
    double vcp_y = ypc-y;
    
    double direction_a = gaiseki(vca_x,vca_y,vap_x,vap_y);
    double direction_b = gaiseki(vab_x,vab_y,vbp_x,vbp_y);
    double direction_c = gaiseki(vbc_x,vbc_y,vcp_x,vcp_y);
    
    direction_a/=fabs(direction_a);
    direction_b/=fabs(direction_b);
    direction_c/=fabs(direction_c);
    
    if(direction_a==direction_b&&direction_b==direction_c)return true;
    else return false;

}



int main(){
    int n;
    while(cin>>n){
        for(int i=0; i<n; i++){
            double xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
            cin>>xp1>>yp1>>xp2>>yp2>>xp3>>yp3>>xk>>yk>>xs>>ys;
            bool in_bega = inside_outside_of_triangle(xp1, yp1, xp2, yp2, xp3, yp3, xs, ys);
            bool in_altair = inside_outside_of_triangle(xp1, yp1, xp2, yp2, xp3, yp3, xk, yk);
            if((in_bega&&!in_altair)||(!in_bega&&in_altair))cout<<"OK"<<endl;
            else cout<<"NG"<<endl;
        }
   
    }
}