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<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);
  }
};

struct segment{
  point a,b;
};

double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}

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 ccw(point p0, point p1, point p2){
  point a = p1 - p0;
  point b = p2 - p0;
  if(cross(a,b)>EPS)return +1;
  if(cross(a,b)<EPS)return -1;
  if(dot(a,b)<-EPS)return +2;
  if(a.x*a.x+a.y*a.y<b.x*b.x+b.y*b.y)return -2;
  return 0;
}


//時計回りに辺を構築する。
vector<segment> construct_edge(point* p, int n){
  vector<segment>seg,seg2;
  segment temp;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i!=j){
	temp.a=p[i];
	temp.b=p[j];
	seg.push_back(temp);
      }
    }
  }

  int t=seg.size();
  for(int i=0;i<t;i++){
    int fg=0;
    for(int j=0;j<t;j++){
      if(i!=j && seg[i].b.x==seg[j].a.x && seg[i].b.y==seg[j].a.y){
	if(ccw(seg[i].a,seg[i].b,seg[j].b)==1){
	  fg=1;
	  break;
	}
      }
    }
    if(!fg)seg2.push_back(seg[i]);
  }
  return seg2;
}
/*
点と多角形の内外判定

ps 多角形の辺
p  点
n  多角形の辺の数

点が多角形に含まれれば1,
そうでなければ0を返す。
*/
int point_contain(vector<segment> ps, point p, int n){
  point q;
  q.x=100000000;
  q.y=p.y;
  int cnt=0;
  for(int i=0;i<n;i++){
    if(ps[i].a.y==ps[i].b.y && ps[i].b.y==p.y)return 0;
    cnt+=is_intersected_ls(ps[i].a,ps[i].b,p,q);
  }
  return cnt%2;
}

int main(void){
  int n;
  point p[3],k,s;
  vector<segment>seg;

  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;

    seg=construct_edge(p,3);

    if(point_contain(seg,k,3)!=point_contain(seg,s,3))cout << "OK" << endl;
    else cout << "NG" << endl;
    
  }

  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

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 vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

#include <complex>
typedef complex<double> Point;
const double EPS = 1e-8;

// 入力ストリームから実数二つをとって Point へ
istream& operator >> ( istream &s, Point &a )
{
	double r, i;
	s >> r >> i;
	a = Point( r, i );
	return s;
}

// 外積（クロス積）
double cross( const Point &a, const Point &b )
{
	return a.real() * b.imag() - a.imag() * b.real();
}

// CCW 関数　a -> b -> c と進むとき、反時計回りなら 1, 直進なら 0, 時計回りなら -1
// include : cross
int ccw( const Point &a, const Point &b, const Point &c )
{
	if ( cross( ( b - a ), ( c - a ) ) < -EPS )
	{
		return -1;
	}
	else if ( EPS < cross( ( b - a ), ( c - a ) ) )
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

// 点 p が多角形 qs の内部にあるか ( Winding Number Algorithm) :TODO
// include : ccw
bool point_in_polygon( const Point &p, const vector<Point> &qs )
{
	const int N = qs.size();
	
	int wn = 0;
	for ( int i = 0; i < N; ++i )
	{
		const Point &s = qs[i], &t = qs[ ( i + 1 ) % N ];
		if ( s.imag() - EPS <= t.imag() && s.imag() - EPS < p.imag() && p.imag() + EPS < t.imag() ) // 上向きの辺
		{
			wn += ccw( s, p, t ) == -1;
		}
		else if ( t.imag() - EPS <= s.imag() && t.imag() - EPS < p.imag() && p.imag() + EPS < s.imag() )
		{
			wn -= ccw( t, p, s ) == -1;
		}
	}
	return wn;
};

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	int n;
	cin >> n;
	REP( i, 0, n )
	{
		vector<Point> tri( 3 );
		REP( j, 0, 3 )
		{
			cin >> tri[j];
		}
		Point s, t;
		cin >> s >> t;

		cout << ( point_in_polygon( s, tri ) ^ point_in_polygon( t, tri ) ? "OK" : "NG" ) << endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;struct P{float x,y;int operator-=(P&a){x-=a.x;y-=a.y;}};P A,B,C,S,G;int X(P S){C.x=(B.y*S.x-B.x*S.y)/(A.x*B.y-A.y*B.x);C.y=(A.y*S.x-A.x*S.y)/(A.y*B.x-A.x*B.y);return C.x>0&C.y>0&C.x+C.y<1;}main(){for(cin>>A.x;cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>S.x>>S.y>>G.x>>G.y;){A-=C;B-=C;S-=C;G-=C;X(S)^X(G)?cout<<"OK\n":cout<<"NG\n";}}

C++: #include <bits/stdc++.h>

using namespace std;

class Point {
public:
	int x, y;
};

Point PointData[5];


int isExistTriangle(const Point& p) {

	int r1 = (PointData[1].x - PointData[0].x) * (p.y - PointData[0].y) - (p.x - PointData[0].x) * (PointData[1].y - PointData[0].y);
	int r2 = (PointData[2].x - PointData[1].x) * (p.y - PointData[1].y) - (p.x - PointData[1].x) * (PointData[2].y - PointData[1].y);
	int r3 = (PointData[0].x - PointData[2].x) * (p.y - PointData[2].y) - (p.x - PointData[2].x) * (PointData[0].y - PointData[2].y);

	if (r1 > 0 && r2 > 0 && r3 > 0) {
		return 1;
	}
	if (r1 < 0 && r2 < 0 && r3 < 0) {
		return 1;
	}
	return -1;
}

int main(void) {
	int n, flag1, flag2;

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 5; j++) {
			cin >> PointData[j].x >> PointData[j].y;
		}
		
		flag1 = isExistTriangle(PointData[3]);
		flag2 = isExistTriangle(PointData[4]);
		//cout << flag1 << ends << flag2 << endl;
		if (flag1*flag2 == 1) {
			cout << "NG" << endl;
		}
		else {
			cout << "OK" << endl;
		}
	}

	return 0;
}