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 <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef complex<int> Point;

int cross(Point a,Point b)
{
	return imag(conj(a)*b);
}

bool in(Point p,Point t[])
{
	int c[3];
	rep(i,3)
		c[i]=cross(t[(i+1)%3]-t[i],p-t[i]);
	return count_if(c,c+3,bind2nd(less<int>(),0))%3==0;
}

int main()
{
	int n;
	cin>>n;
	rep(tc,n){
		Point t[3],m,w;
		rep(i,3)
			cin>>real(t[i])>>imag(t[i]);
		cin>>real(m)>>imag(m)>>real(w)>>imag(w);
		bool inm=in(m,t);
		bool inw=in(w,t);
		puts(inm!=inw?"OK":"NG");
	}
	
	return 0;
}

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

int x,y,x2,y2,x3,y3,xk,yk,xs,ys;

double len(int xa, int ya,int xb,int yb){
  return sqrt( (xa-xb)*(xa-xb) + (ya-yb)*(ya-yb) );
}

double flon(int xa,int ya, int xb, int yb ,int xc ,int yc){
  double l1,l2,l3,s;
  l1 = len(xa,ya,xb,yb);
  l2 = len(xb,yb,xc,yc);
  l3 = len(xc,yc,xa,ya);
  s = (l1+l2+l3)/2;

  return sqrt( s*(s-l1)*(s-l2)*(s-l3) );
}

bool interk(void){
  if( fabs(flon(x,y,x2,y2,xk,yk) + flon(x,y,x3,y3,xk,yk) + flon(x2,y2,x3,y3,xk,yk) - flon(x,y,x2,y2,x3,y3) ) < 1e-10 )return true;
  else return false;
}

bool inters(void){
  if( fabs(flon(x,y,x2,y2,xs,ys) + flon(x,y,x3,y3,xs,ys) + flon(x2,y2,x3,y3,xs,ys) - flon(x,y,x2,y2,x3,y3) ) < 1e-10 )return true;
  else return false;
}

int main(){
  int n;

  cin >> n;
  while(n){
    n--;
    cin >> x >> y >> x2 >> y2 >> x3 >> y3 >> xk >> yk >> xs >> ys;

    if( interk() != inters() )cout << "OK" << endl;
    else cout << "NG" << endl;
  }
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
#include<complex>

typedef complex<double> Point;
double dot(Point a, Point b){
  return real(conj(a) * b);
}
double cross(Point a, Point b){
  return imag(conj(a) * b);
}
int ccw(Point a, Point b, Point c){
  b -= a; c -= a;
  if(cross(b, c) > EPS) return 1;
  if(cross(b, c) < -EPS) return -1;
  if(dot(b, c) < 0) return +2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}
enum{ OUT, ON, IN };
int contains(Point a, Point b, Point c, Point p){
  int A = ccw(a, b, p);
  int B = ccw(b, c, p);
  int C = ccw(c, a, p);
  if(A == B && B == C && abs(A) == 1) return IN;
  return OUT;
}

int main(){
  int N;
  cin >> N;
  while(N--){
    Point a[3];
    Point b[2];
    REP(i, 3) cin >> a[i].real() >> a[i].imag();
    REP(i, 2) cin >> b[i].real() >> b[i].imag();
    if(abs(ccw(a[0], a[1], a[2])) == 1 && contains(a[0], a[1], a[2], b[0]) != contains(a[0], a[1], a[2], b[1])){
      cout << "OK" << endl;
    }else{
      cout << "NG" << endl;
    }
  }
  return 0;
}

C++: #include<cstdio>
#include<complex>
typedef std::complex<double>P;
double C(P a,P b){return a.real()*b.imag()-a.imag()*b.real();}
int F(P p,P a,P b,P c)
{
	double x=C(b-a,p-a),y=C(c-b,p-b),z=C(a-c,p-c);
	return x>0&&y>0&&z>0||x<0&&y<0&&z<0;
}
int main()
{
	P p[5];
	int n,i,x,y;
	for(scanf("%d",&n);n--;)
	{
		for(i=0;i<5;++i)scanf("%d%d",&x,&y),p[i]=P(x,y);
		puts((F(p[3],p[0],p[1],p[2])^F(p[4],p[0],p[1],p[2]))?"OK":"NG");
	}
}