Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		input := strings.Split(scanner.Text(), " ")
		buf := make([]float64, len(input))
		for j := range buf {
			buf[j], _ = strconv.ParseFloat(input[j], 64)
		}
		p1 := complex(buf[0], buf[1])
		p2 := complex(buf[2], buf[3])
		p3 := complex(buf[4], buf[5])
		pk := complex(buf[6], buf[7])
		ps := complex(buf[8], buf[9])
		kin := isAtSameSide(p3, pk, []complex128{p1, p2}) &&
			isAtSameSide(p1, pk, []complex128{p2, p3}) &&
			isAtSameSide(p2, pk, []complex128{p3, p1})
		sin := isAtSameSide(p3, ps, []complex128{p1, p2}) &&
			isAtSameSide(p1, ps, []complex128{p2, p3}) &&
			isAtSameSide(p2, ps, []complex128{p3, p1})
		if (kin || sin) && !(kin && sin) {
			fmt.Println("OK")
		} else {
			fmt.Println("NG")
		}
	}
}

func isAtSameSide(a, b complex128, line []complex128) bool {
	sa := (real(line[1]) - real(line[0]))*(imag(a)-imag(line[0]))+
		(imag(line[1])-imag(line[0]))*(real(line[0])-real(a))
	sb := (real(line[1]) - real(line[0]))*(imag(b)-imag(line[0]))+
		(imag(line[1])-imag(line[0]))*(real(line[0])-real(b))
	return (sa > 0 && sb > 0) || (sa < 0 && sb < 0)
}

C++: /**************** Geometrical Library ****************/

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

#define	EPS	1e-9

enum {CCW=1,CW=-1,ON=0};

#define	mp	make_pair
#define	pb	push_back

using namespace std;

class Point{
public:
	double x,y;
	Point(){}
	Point(double xx,double yy):x(xx),y(yy){}
};

class Line:public vector<Point>{
public:
	Line(const Point &a,const Point &b){
		pb(a),pb(b);
	}
};

class Segment:public Line{
public:
	Segment(const Point &a,const Point &b):Line(a,b){}
};

class Polygon:public vector<Point>{};

class Circle{
public:
	Point c;
	double r;
	Circle(const Point &cc,double rr) : c(cc),r(rr){}
};

Point &operator +=(Point &a,const Point &b){
	a.x+=b.x,a.y+=b.y;
	return a;
}

Point &operator -=(Point &a,const Point &b){
	a.x-=b.x,a.y-=b.y;
	return a;
}

Point &operator *=(Point &a,double c){
	a.x*=c,a.y*=c;
	return a;
}

Point &operator /=(Point &a,double c){
	a.x/=c,a.y/=c;
	return a;
}

Point operator +(const Point &a,const Point &b){
	Point c=a;
	return c+=b;
}

Point operator -(const Point &a,const Point &b){
	Point c=a;
	return c-=b;
}

Point operator *(double c,const Point &a){
	Point b=a;
	return b*=c;
}

Point operator /(const Point &a,double c){
	Point b=a;
	return b/=c;
}

bool operator <(const Point &a,const Point &b){
	return (a.x==b.x)?(a.y<b.y):(a.x<b.x);
}

bool operator >(const Point &a,const Point &b){
	return b<a;
}

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

int ccw(const Point &a,Point b,Point c){
	b-=a,c-=a;
	double rotdir=cross(b,c);
	if(rotdir>EPS)		return CCW;
	if(rotdir<-EPS)		return CW;
	return ON;
}

/**************** Library END ****************/

#include<cstdio>

int main(){
	int n;	scanf("%d",&n);
	while(n--){
		Point a,b,c,star[2];
		scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
			&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&star[0].x,&star[0].y,&star[1].x,&star[1].y);
		bool in[2];
		for(int i=0;i<2;i++){
			int cnt=0;
			cnt+=ccw(a,b,star[i]);
			cnt+=ccw(b,c,star[i]);
			cnt+=ccw(c,a,star[i]);
			in[i]=(cnt==3*CCW || cnt==3*CW);
		}
		puts(in[0]==in[1]?"NG":"OK");
	}
	return 0;
}

C++: #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)cout<<"OK"<<endl;
            else cout<<"NG"<<endl;
        }
   
    }
}