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 <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }
 
typedef complex<double> P;

double triangleArea(P a, P b, P c)
{
    b -= a;
    c -= a;
    
    return (0.5 * abs(b.imag() * c.real() - c.imag() * b.real()));
}

// _ªOp`ÌÉ é©
bool isInTriangle(P p[3], P x)
{
    int i;
    double S = triangleArea(p[0], p[1], p[2]);
    
    rep(i, 3) S -= triangleArea(x, p[i], p[(i + 1) % 3]);
    
    return abs(S) < EPS;
}
 
int main()
{
    int n;
        cin >> n;
        
        
        while(n--)
        {
                P p[3];
                P k, s;
                
                rep(i, 3) cin >> p[i].real() >> p[i].imag();
                cin >> k.real() >> k.imag() >> s.real() >> s.imag();
        
                if(isInTriangle(p, k) ^ isInTriangle(p, s))
                {
                        cout << "OK" << endl;
                }
                else
                {
                        cout << "NG" << endl;
                }
        }
}

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

double x[5], y[5];

bool check() {
  double xa[3], ya[3], s[3];
  bool in[2], b[3];
  for (int i=0; i<3; i++) {
    xa[i] = y[(i+1)%3] - y[i];
    ya[i] = -x[(i+1)%3] + x[i];
    s[i] = xa[i]*x[i] + ya[i]*y[i];
  }
  for (int i=0; i<2; i++) {
    for (int j=0; j<3; j++) {
      b[j] = (xa[j]*x[i+3] + ya[j]*y[i+3] < s[j]);
    }
    in[i] = (b[0] == b[1] && b[1] == b[2]);
  }
  return (in[0] != in[1]);
}

int main() {
  int n;
  cin >> n;
  for (int i=0; i<n; i++) {
    for (int j=0; j<5; j++) {
      cin >> x[j] >> y[j];
    }
    if (check()) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}

C++: #include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
 
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 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;
}

int is_intersected_ls(point p1, point p2, point p3, point p4) {
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0)&&
         (ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

int is_point_on_line(point a, point b, point c) {
  return cross(b-a, c-a)==0.0 &&
         (dot(b-a, c-a) > -EPS) &&
         (dot(a-b, c-b) > -EPS);
}

int inside(point p, vector<point> ps, int n){
  segment t;
  t.a=t.b=p;
  t.b.x=DBL_MAX;
  ps.push_back(ps[0]);
  double ymx=-DBL_MAX,ymn=DBL_MAX;
  for(int i=0;i<n;i++){
    ymx=max(ymx,ps[i].y);
    ymn=min(ymn,ps[i].y);
  }
  if(t.a.y<=ymn||t.a.y>=ymx)return 0;

  int cnt1=0;
  for(int i=0;i<n;i++)
    if(is_point_on_line(t.a,t.b,ps[i]))cnt1++;
  
  int cnt=0;
  for(int i=0;i<n;i++)
    if(is_intersected_ls(ps[i],ps[i+1],t.a,t.b))cnt++;

  return (cnt-cnt1)%2;
}

int main(void){
  int n;
  point k,s,in;
  vector<point>p; 

  cin >> n;
  while(n--){
    p.clear();
    for(int i=0;i<3;i++){
      cin >> in.x >> in.y;
      p.push_back(in);
    }     

    cin >> k.x >> k.y >> s.x >> s.y;

    if(inside(k,p,3)!=inside(s,p,3))cout << "OK" << endl;
    else cout << "NG" << endl;
     
  }
 
  return 0;
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

const double EPS = 1e-8;
const double INF = 1e12;

// ½ÊãÌ_ExNg
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);
	}
}

// OÏ
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);
	}
};

// ½p`
typedef vector<P> G;

// ~
struct C{
	P p;
	double r;
	C(const P& p, double r) : p(p), r(r) {}
};

int ccw(P a, P b, P c)
{
	b -= a;
	c -= a;
	if(cross(b, c) > 0)   return +1; // ½vñè
	if(cross(b, c) < 0)   return -1; // vñè
	if(dot(b, c) < 0)     return +2; // c--a--b
	if(norm(b) < norm(c)) return -2; // a--b--c
	return 0;
}

int main()
{
	int n;
	scanf("%d", &n);
	rep(i, n){
		P p[5];
		rep(j, 5)
			scanf("%lf%lf", &p[j].real(), &p[j].imag());
		
		bool ok = true;
		rep(j, 2){
			int ans;
			rep(k, 3){
				int tmp = ccw(p[k], p[(k+1)%3], p[3+j]);
				if(!k)
					ans = tmp;
				else if(ans*tmp < 0){
					ok = !ok;
					break;
				}
			}
		}
		
		puts(ok ? "NG" : "OK");
	}
	
	return 0;
}