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;
typedef long long ll;
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;

// OÏ
double cross(P a, P b)
{	return a.real() * b.imag() - b.real() * a.imag();	}

// àÏ
double dot(P a, P b)
{	return a.real() * b.real() + a.imag() * b.imag();	}

// _ÆüªÌ£
double dist(P a, P b, P c)
{
	if(dot(b - a, c - a) < EPS) return abs(c - a);
	if(dot(a - b, c - b) < EPS) return abs(c - b);
	
	return abs(cross(b - a, c - a)) / abs(b - a);
}

// _ªOp`ÌÉ é©
bool isInTriangle(P p[3], P x)
{
	double S = cross(p[1] - p[0], p[2] - p[0]);
	
	rep(i, 3) S -= abs(cross(p[(i + 1) % 3] - p[i], x - p[i]));
	
	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>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define EPS 1e-10
using namespace std;

int main(void){
    int n;
    cin >> n;
    rep(i,n) {
        int count = 0;
        double x[5],y[5],a,b,c,d,p,q,det,ansx;
        for(int k=0;k<5;k++) {
            cin >> x[k] >> y[k];
        }
        rep(j,3) {
            if(j != 2) {
                a = y[j]-y[j+1];  b = x[j+1]-x[j];
                p = x[j+1]*y[j]-x[j]*y[j+1];
                c = y[3]-y[4];  d = x[4]-x[3];
                q = x[4]*y[3]-x[3]*y[4];
                //係数についての行列式
                det = a*d-c*b;
                //det=0で解は存在しない(この問題については２線分は同一直線上にないから
                if(fabs(det) > EPS){
                    ansx = (d*p - b*q)/det;
                    if((x[j] - ansx)*(x[j+1] - ansx) <= EPS && (x[3] - ansx)*(x[4] - ansx) <= EPS && fabs(ansx - x[j]) > EPS && fabs(ansx - x[j+1]) > EPS ) {
                        count++;
                    }
                }
            } else {
                a = y[j]-y[0];  b = x[0]-x[j];
                p = x[0]*y[j]-x[j]*y[0];
                c = y[3]-y[4];  d = x[4]-x[3];
                q = x[4]*y[3]-x[3]*y[4];
                //係数についての行列式
                det = a*d-c*b;
                if(fabs(det) > EPS){
                    ansx = (d*p - b*q)/det;
                    if((x[j] - ansx)*(x[0] - ansx) <= EPS && (x[3] - ansx)*(x[4] - ansx) <= EPS && fabs(ansx - x[j]) > EPS && fabs(ansx - x[0]) > EPS ) {
                        count++;
                    }
                }
            }
        }
        if(count == 1) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
}