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++: #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<iomanip>
#include<bitset>
#include<utility>
#include<list>
#include<map>
#include<set>
#include<cstring>
#include<sstream>
#include<cctype>
using namespace std;
const double EPS=1e-5;
const double INF=1e9;
typedef complex<double>P;
namespace std{
    bool operator<(const P& a,const P& b){
        return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
    }
}
#define EQ(a,b) (fabs((a)-(b))<EPS)
#define EQV(a,b) (EQ(real(a),real(b))&&EQ(imag(a),imag(b)))
double cross(const P &a,const P &b){
    return imag(conj(a)*b);
}
double dot(const P &a,const P &b){
    return real(conj(a)*b);
}

struct L:public vector<P>{
    L(const P &a,const P &b){
        push_back(a);push_back(b);
    }
    L(){}
};

typedef vector<P>G;

struct C{
    P p;double r;
    C(const P &p_,double r_):p(p_),r(r_){}
    C(){}
};

int ccw(P a,P b,P c){
    b-=a;c-=a;
    if(cross(b,c)>0)return 1;///counter clockwise
    if(cross(b,c)<0)return -1;///clockwise
    if(dot(b,c)<0)return 2;///c--a--b on line
    if(norm(b)<norm(c))return -2;///a--b--c on line
    return 0;
}
bool orthogonal(P &p,P &q){
    return EQ(dot(p,q),0.0);
}
bool intersectLL(const L &l,const L &m){
    return abs(cross(l[1]-l[0],m[1]-m[0]))>EPS||///non-parallel
        abs(cross(l[1]-l[0],m[0]-l[0]))<EPS;///same line
}
bool intersectLS(const L &l,const L &s){
    return cross(l[1]-l[0],s[0]-l[0])*///s[0] is left of l
        cross(l[1]-l[0],s[1]-l[0])<EPS;///s[1] is right of l
}
bool intersectLP(const L &l,const P &p){
    return abs(cross(l[1]-p,l[0]-p))<EPS;
}
bool intersectSS(const L &s,const L &t){
    return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1])<=0&&
        ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1])<=0;
}
bool intersectSP(const L &s,const P &p){
    return abs(abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]))<EPS;
    ///triangle inequality
}
P projection(const L &l,const P &p){
    double t=dot(p-l[0],l[0]-l[1])/norm(l[0]-l[1]);
    return l[0]+t*(l[0]-l[1]);
}
P reflection(const L &l,const P &p){
    return p+(projection(l,p)-p)*2.0;
}
double distanceLP(const L &l,const P &p){
    return abs(p-projection(l,p));
}
double distanceLL(const L &l,const L &m){
    return intersectLL(l,m)?0:distanceLP(l,m[1]);
}
double distanceLS(const L &l,const L &s){
    if(intersectLS(l,s))return 0;
    return min(distanceLP(l,s[0]),distanceLP(l,s[1]));
}
double distanceSP(const L &s,const P &p){
    const P r=projection(s,p);
    if(intersectSP(s,r))return abs(r-p);
    return min(abs(s[0]-p),abs(s[1]-p));
}
double distanceSS(const L &s,const L &t){
    if(intersectSS(s,t))return 0;
    return min(min(distanceSP(s,t[0]),distanceSP(s,t[1])),
            min(distanceSP(t,s[0]),distanceSP(t,s[1])));
}
P crossPoint(const L &l,const L &m){
    double A=cross(l[1]-l[0],m[1]-m[0]);
    double B=cross(l[1]-l[0],l[1]-m[0]);
    if(abs(A)<EPS&&abs(B)<EPS)return m[0];///same line
    ///if(abs(A)<EPS)assert(false);
    return m[0]+B/A*(m[1]-m[0]);

}

P extreme(const G &g,const L &l){
    int k=0;
    for(int i=1;i<g.size();i++){
        if(dot(g[i],l[1]-l[0])>dot(g[k],l[1]-l[0]))k=i;
    }
    return g[k];
}

G andrewScan(G s){
    G u,l;
    if(s.size()<3)return s;
    sort(s.begin(),s.end());
    u.push_back(s[0]);
    u.push_back(s[1]);

    l.push_back(s[s.size()-1]);
    l.push_back(s[s.size()-2]);

    for(int i=2;i<s.size();i++){
        for(int n=u.size();n>=2&&ccw(u[n-2],u[n-1],s[i])!=-1;n--){
            u.pop_back();
        }
        u.push_back(s[i]);
    }

    for(int i=s.size()-3;i>=0;i--){
        for(int n=l.size();n>=2&&ccw(l[n-2],l[n-1],s[i])!=-1;n--){
            l.pop_back();
        }
        l.push_back(s[i]);
    }
    reverse(l.begin(),l.end());
    for(int i=u.size()-2;i>=1;i--)l.push_back(u[i]);
    return l;
}
/*
IN 2
ON 1
OUT 0
*/
int contains(G g,P p){
    int n=g.size();
    bool x=false;
    for(int i=0;i<n;i++){
        P a=g[i]-p,b=g[(i+1)%n]-p;
        if(abs(cross(a,b))<EPS&&dot(a,b)<EPS)return 1;
        if(imag(a)>imag(b))swap(a,b);
        if(imag(a)<EPS&&EPS<imag(b)&&cross(a,b)>EPS)x=!x;
    }
    return (x?2:0);
}

int main(){
    int N;
    scanf("%d",&N);
    while(N--){
        G g(3);
        P o,h;
        double x,y;
        for(int i=0;i<3;i++){
            scanf("%lf%lf",&x,&y);
            g[i]=P(x,y);
        }
        scanf("%lf%lf",&x,&y);
        o=P(x,y);
        scanf("%lf%lf",&x,&y);
        h=P(x,y);
        if(contains(g,o)+contains(g,h)==2)puts("OK");
        else puts("NG");
    }
    return 0;
}

C++: // 2011/03/03 Tazoe

#include <iostream>
using namespace std;

int trian2(int x1, int y1, int x2, int y2)
{
	int s2 = x1*y2-x2*y1;

	if(s2<0)
		s2 = -s2;

	return s2;
}

bool insid(int x1, int y1, int x2, int y2, int x3, int y3, int x, int y)
{
	int s = trian2(x2-x1, y2-y1, x3-x1, y3-y1);

	int s1 = trian2(x1-x, y1-y, x2-x, y2-y);
	int s2 = trian2(x2-x, y2-y, x3-x, y3-y);
	int s3 = trian2(x3-x, y3-y, x1-x, y1-y);

	if(s==s1+s2+s3)
		return true;
	else
		return false;
}

int main()
{
	int n;
	cin >> n;

	for(int i=0; i<n; i++){
		int xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
		cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;

		bool ink = insid(xp1, yp1, xp2, yp2, xp3, yp3, xk, yk);
		bool ins = insid(xp1, yp1, xp2, yp2, xp3, yp3, xs, ys);

		if(ink!=ins)
			cout << "OK" << endl;
		else
			cout << "NG" << endl;
	}

	return 0;
}