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>
using namespace std;

struct Point
{
	Point(int x, int y):x(x),y(y),z(0){}
	Point():x(0),y(0),z(0){}
	int x,y,z;
};
inline bool isRight( Point &p, Point &a, Point &b ){
	return ( (b.x-a.x)*(p.y-a.y) - (b.y-a.y)*(p.x-a.x) ) > 0;
}
bool isInside( Point &p, vector<Point> &vp ){
	for(unsigned int i = 1; i < vp.size(); ++i){
		if( !isRight( p, vp[i-1], vp[i] ) )
			return false;
	}
	return isRight( p, vp[vp.size()-1], vp[0] );
}

int main()
{
	int n;
	cin >> n;
	for(int X = 0; X < n; ++X ){
		Point A, B, C, ken, ori;
		bool  bKenInside = false, bOriInside = false;
		vector<Point> triangle;
		cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y >> ken.x >> ken.y >> ori.x >> ori.y;
		triangle.push_back(A);triangle.push_back(B);triangle.push_back(C);

		bKenInside = isInside( ken, triangle );
		bOriInside = isInside( ori, triangle );
		if( bKenInside ^ bOriInside )
			cout << "OK\n";
		else
			cout << "NG\n";
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a) * b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
	return l.first + t * (l.first - l.second);
}

int ccw(xy_t a, xy_t b, xy_t c){
	b -= a;
	c -= a;
	if(cross(b, c) > 0) return 1;
	if(cross(b, c) < 0) return -1;
	if(dot(b, c) < 0) return 2;
	if(norm(b) < norm(c)) return -2;
	return 0;
}

bool intersectSP(const line &l, const xy_t &p){
	return abs(l.first- p) + abs(l.second - p) - abs(l.first - l.second) < EPS;
}

bool intersectSS(const line &s, const line &t){
	return ccw(s.first, s.second, t.first) * ccw(s.first, s.second, t.second) <= 0 &&
		ccw(t.first, t.second, s.first) * ccw(t.first, t.second, s.second) <= 0;
}

double distanceSP(line s, xy_t p){
	const xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

int main(){
	int n;
	double xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
	line s, l[3];
	cin >> n;
	rep(t, n){
		cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
		l[0] = line(xy_t(xp1, yp1), xy_t(xp2, yp2));
		l[1] = line(xy_t(xp2, yp2), xy_t(xp3, yp3));
		l[2] = line(xy_t(xp3, yp3), xy_t(xp1, yp1));
		s = line(xy_t(xs, ys), xy_t(xk, yk));
		int cnt = 0;
		rep(i, 3) if(intersectSS(l[i], s)) cnt++;
		if(cnt % 2 == 0) cout << "NG" << endl;
		else cout << "OK" << endl;
	}
	return 0;
}

C++: //47
#include<iostream>
#include<complex>

using namespace std;

typedef complex<double> P;

bool in(P x,P *a){
  bool sg[2]={};
  for(int i=0;i<3;i++){
    P e=a[(i+1)%3]-a[i];
    P d=x-a[i];
    sg[e.real()*d.imag()-e.imag()*d.real()<0]=true;
  }
  return sg[0]^sg[1];
}

int main(){
  int n;
  cin>>n;
  while(n--){
    P p[5];
    for(int i=0;i<5;i++){
      double x,y;
      cin>>x>>y;
      p[i]=P(x,y);
    }
    cout<<(in(p[3],p)^in(p[4],p)?"OK":"NG")<<endl;
  }
  return 0;
}

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

double EPS = 1e-9; 

struct Point {
    double x, y;
};

struct Line {
	Point s, e;
	Line (Point _s, Point _e) {
		s = _s; e = _e;
	}
};

double distPointLine(const Point& A, const Line& l) {
	double a = (l.s.y - l.e.y)/(l.s.x - l.e.x);
	double c = (-1)*a*l.s.x - l.s.y;
	return fabs(a * A.x + A.y + c)/sqrt(a*a + 1.0);
}

enum { IN, ON, OUT };
int PointInTri(const vector<Point>& tri, const Point& p) {
    int cnt = 0;
    for (int i=1; i<4; i++) {
        Point p0 = tri[i-1], p1 = tri[i%3];
        bool flag0x = (p.x <= p0.x), flag0y = (p.y <= p0.y);
        bool flag1x = (p.x <= p1.x), flag1y = (p.y <= p1.y);
        
        Line p0top1(p0, p1);
        if (distPointLine(p, p0top1) <= EPS) return ON;
         
        if (flag0y != flag1y) {
            if ( flag1x && flag0x) {
                cnt += flag0y ? -1 : 1;
            } else if (p.x <= ( p0.x+(p1.x-p0.x)*(p.y-p0.y)/(p1.y-p0.y) ) ) {
                cnt += flag0y ? -1 : 1;
            }
        }
    }
    return cnt!=0 ? IN : OUT;
}
 
int main() {
    int n; cin >> n;
     
    vector<Point> tri(3);
    for (int i=0; i<n; i++) {
        cin >> tri[0].x >> tri[0].y >> tri[1].x >> tri[1].y >> tri[2].x >> tri[2].y;
        Point p1; cin >> p1.x >> p1.y;
        Point p2; cin >> p2.x >> p2.y;
        bool flag1 = (PointInTri(tri, p1) == IN), flag2 = (PointInTri(tri, p2) == IN);
        if ( flag1 != flag2 ) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
     
    return 0;
}