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;

double dot(P a, P b)
{	return a.real() * b.real() + a.imag() * b.imag();	}

double cross(P a, P b)
{	return a.real() * b.imag() - b.real() * a.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);
}

bool isInTriangle(P p[3], P x)
{
	double a = abs(p[0] - p[1]) * dist(p[0], p[1], x) / 2.0;
	double b = abs(p[1] - p[2]) * dist(p[1], p[2], x) / 2.0;
	double c = abs(p[2] - p[0]) * dist(p[2], p[0], x) / 2.0;
	
	double S = abs(p[0] - p[1]) * dist(p[0] ,p[1], p[2]) / 2.0;
	
	return abs(a + b + c - 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<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);
  }
};

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 main(void){
  int n;
  point p[3],k,s;

  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;
    int cnt=0;
    for(int i=0;i<3;i++)
      for(int j=i+1;j<3;j++)
	if(i!=j)
	  cnt+=is_intersected_ls(p[i],p[j],k,s);
    
    if(cnt%2)cout << "OK" << endl;
    else cout << "NG" << endl;
    
  }

  return 0;
}

C++: #include <iostream>
#include <math.h>

using namespace std;

double square_calc(double x1, double y1, double x2, double y2, double x3, double y3)
{
	double square = 0;
	double a = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
	double b = sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
	double c = sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
	double s = (a + b + c) / 2;
	return(sqrt(s * (s - a ) * (s - b) * (s - c)));
}

void solve()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i)
	{
		double xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
		cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
		double square = square_calc(xp1, yp1, xp2, yp2, xp3, yp3);
		double square1 = square_calc(xk, yk, xp1, yp1, xp2, yp2) + square_calc(xk, yk, xp1, yp1, xp3, yp3) + square_calc(xk, yk, xp2, yp2, xp3, yp3);
		double square2 = square_calc(xs, ys, xp1, yp1, xp2, yp2) + square_calc(xs, ys, xp1, yp1, xp3, yp3) + square_calc(xs, ys, xp2, yp2, xp3, yp3);
		if(fabs(square - square1) <= 1e-6 && fabs(square - square2) >= 1e-6 ||
		   fabs(square - square1) >= 1e-6 && fabs(square - square2) <= 1e-6)
		{
			cout << "OK" << endl;
		}
		else
		{
			cout << "NG" << endl;
		}
	}
}

int main()
{
	solve();
	return(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 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 );
}

/*
点と多角形の内外判定

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

点が多角形に含まれれば1,
そうでなければ0を返す。
*/
int point_contain(segment* ps, point p, int n){
  int cnt=0;
  point q;
  q.x=10000;
  q.y=10000;
  for(int i=0;i<n;i++)
	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;
  segment seg[3];

  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;
    int cnt=0,l=0;
    for(int i=0;i<3;i++)
      for(int j=i+1;j<3;j++)
	if(i!=j){
	  seg[i].a=p[i];
	  seg[i].b=p[j];
	  l++;
	}
     

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

  return 0;
}