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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.1415926535
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

main(){
  int n;
  cin>>n;
  while(n--){
    int xp[3],yp[3],xm[2],ym[2];
    rep(i,3)cin>>xp[i]>>yp[i];

    rep(i,2)cin>>xm[i]>>ym[i];

    bool fe[2];
    fe[0]=fe[1]=true;

    rep(i,3){
      int nx1=xp[(i+1)%3]-xp[i],ny1=yp[(i+1)%3]-yp[i];
      int nx2=xp[(i+2)%3]-xp[i],ny2=yp[(i+2)%3]-yp[i];
      double nx1ab=sqrt(nx1*nx1+ny1*ny1),nx2ab=sqrt(nx2*nx2+ny2*ny2);
      double ang=(1.0*(nx1*nx2+ny1*ny2)/nx1ab/nx2ab);
      //cout<<"ang "<<ang;
      rep(j,2){
	int nxm=xm[j]-xp[i],nym=ym[j]-yp[i];
	double nxmab=sqrt(nxm*nxm+nym*nym);
	double nang=(1.0*(nxm*nx1+nym*ny1)/nxmab/nx1ab);
	//cout<<" "<<nang<<" ";
	if(nang<ang)fe[j]=false;
	nang=(1.0*(nxm*nx2+nym*ny2)/nxmab/nx2ab);
	if(nang<ang)fe[j]=false;
	//cout<<nang<<endl;
      }
    }
    //cout<<fe[0]<<fe[1];
    if(fe[0]==fe[1])cout<<"NG";
    else cout<<"OK";
    cout<<endl;
  }
}

C++: #include<iostream>
using namespace std;
int it(long p1x, long p1y,long p2x, long p2y,long p3x, long p3y,long p4x, long p4y){
return ((p1x-p2x)*(p3y-p1y)+(p1y-p2y)*(p1x-p3x))*((p1x-p2x)*(p4y-p1y)+(p1y-p2y)*(p1x-p4x));
}
int main(){
long n,k,i,s,xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys;
cin>>n;
for(i=0;i<n;i++){
cin>>xp1>>yp1>>xp2>>yp2>>xp3>>yp3>>xk>>yk>>xs>>ys;
k=-1;
if(it(xp1,yp1,xp2,yp2,xk,yk,xp3,yp3)<0)k=1;
if(it(xp2,yp2,xp3,yp3,xk,yk,xp1,yp1)<0)k=1;
if(it(xp3,yp3,xp1,yp1,xk,yk,xp2,yp2)<0)k=1;
s=-1;
if(it(xp1,yp1,xp2,yp2,xs,ys,xp3,yp3)<0)s=1;
if(it(xp2,yp2,xp3,yp3,xs,ys,xp1,yp1)<0)s=1;
if(it(xp3,yp3,xp1,yp1,xs,ys,xp2,yp2)<0)s=1;
if(k*s>0)cout<<"NG"<<endl;else cout<<"OK"<<endl;

}
return 0;
}

C++: #include<iostream>
using namespace std;
long it(long p1x, long p1y,long p2x, long p2y,long p3x, long p3y,long p4x, long p4y){
long k=-1,s=-1;
if((p2x-p1x)*(p3y-p1y)<(p2y-p1y)*(p3x-p1x))k=1;
if((p2x-p1x)*(p4y-p1y)<(p2y-p1y)*(p4x-p1x))k=1;
return k*s;
}
int main(){
long n,k,i,s,xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys;
cin>>n;
for(i=0;i<n;i++){
cin>>xp1>>yp1>>xp2>>yp2>>xp3>>yp3>>xk>>yk>>xs>>ys;
k=-1;
if(it(xp1,yp1,xp2,yp2,xp3,yp3,xk,yk)<0)k=1;
if(it(xp2,yp2,xp3,yp3,xp1,yp1,xk,yk)<0)k=1;
if(it(xp3,yp3,xp1,yp1,xp2,yp2,xk,yk)<0)k=1;
s=-1;
if(it(xp1,yp1,xp2,yp2,xp3,yp3,xs,ys)<0)s=1;
if(it(xp2,yp2,xp3,yp3,xp1,yp1,xs,ys)<0)s=1;
if(it(xp3,yp3,xp1,yp1,xp2,yp2,xs,ys)<0)s=1;
if(k*s>0)cout<<"NG"<<endl;else cout<<"OK"<<endl;
}
return 0;
}

C++: #include <iostream>
#include <utility>
using namespace std;

#define x first 
#define y second 

typedef pair<double,double> pdd;

bool inTriangle(pdd o, pdd tri0, pdd tri1, pdd pts) {
	pdd a, b, c;
	a.x = tri0.x - o.x;
	a.y = tri0.y - o.y;
	b.x = tri1.x - o.x;
	b.y = tri1.y - o.y;
	c.x = pts.x - o.x;
	c.y = pts.y - o.y;

	double s, t;
	t = (c.x * a.y - c.y * a.x) / (b.x * a.y - b.y * a.x);
	s = (c.x * b.y - c.y * b.x) / (b.y * a.x - b.x * a.y);

	if(s >= 0 && t >= 0 && s + t <= 1)
		return true;
	return false;
}

int main() {
	int n;
	cin >> n;
	for(int t = 0; t < n; t++) {
		pdd in[5];
		for(int i = 0; i < 5; i++) {
			cin >> in[i].x >> in[i].y;
		}

		bool flag;
		flag = inTriangle(in[0], in[1], in[2], in[3]) ^ inTriangle(in[0], in[1], in[2], in[4]);
		if(flag)
			cout << "OK" << endl;
		else
			cout << "NG" << endl;
	}
}