#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>

using namespace std;

double EPS = 1e-10;

double add(double a, double b){
if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
return a+b;
}



struct point{

double x, y;

point(){}

point(double x,double y) : x(x) , y(y){}

point operator + (point p){
return point(add(x,p.x), add(y,p.y));
}

point operator - (point p){
return point(add(x,-p.x), add(y,-p.y));
}

point operator * (double d){
return point(x*d,y*d);
}

};



double cross(point a, point b) {
return (a.x * b.y - a.y * b.x);
}



int is_intersected_ls(point a1, point a2, point b1, point b2) {

return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );

}



int main(void){

int n;

point p[3],k,s;

cin >> n;

while(n--){
for(int i=0;i<3;i++)
cin >> p[i].x >> p[i].y;

cin >> k.x >> k.y >> s.x >> s.y;

int cnt=0;

for(int i=0;i<3;i++)
for(int j=i+1;j<3;j++)
cnt+=is_intersected_ls(p[i],p[j],k,s);

if(cnt%2)cout << "OK" << endl;
else cout << "NG" << endl;
}

return 0;

}