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

 double vec_abs(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}

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 inside(point t,point* p,int N){
  int i,count=0,j=0;
  segment lt,lp;

  p[N]=p[0];
  p[N+1]=p[1];

  lt.a=lt.b=t;
  lt.b.x=INT_MAX;

  for(i=1;i<=N;i++){
    lp.a=lp.b=p[i];

    if(!is_intersected_ls(lp.a,lp.b,lt.a,lt.b)){
      if(i==j+1){
	lp.b=p[j];
	if(is_intersected_ls(lp.a,lp.b,lt.a,lt.b))count++;
      }
      else if(ccw(lt.a,lt.b,p[i])*ccw(lt.a,lt.b,p[j])<0)count++;
      j=i;
    }
  }
  return count & 1;
}

int main(void){
  int n;
  point p[5],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;
 
    if(inside(k,p,3)!=inside(s,p,3))cout << "OK" << endl;
    else cout << "NG" << endl;
     
  }
 
  return 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-5;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef long long ll;
#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>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

struct Vector2D{
    double x;
    double y;
};
//???????????????(??????????????¨??????)
#define Vertex2D Vector2D

//?????????????????????(a-b)
Vector2D sub_vector( const Vector2D& a, const Vector2D& b )
{
    Vector2D ret;
    ret.x = a.x - b.x;
    ret.y = a.y - b.y;
    return ret;
}

// ????§???¢??¨?????????????????????(2D?????´???)
// ?????????    0:????§???¢????????´???????????????    1:????§???¢????????´???????????????
int hittest_point_polygon_2d( Vertex2D A, Vertex2D B, Vertex2D C, Vertex2D P ) {

    //??????????????¨??????????????????
    //ABC???????§???¢????????????????????§??????????????\...
    
    Vector2D AB = sub_vector(B, A);
    Vector2D BP = sub_vector(P, B);

    Vector2D BC = sub_vector(C, B);
    Vector2D CP = sub_vector(P, C);

    Vector2D CA = sub_vector(A, C);
    Vector2D AP = sub_vector(P, A);

    //??????    Z?????????????¨????????????°????????§???
    double c1 = AB.x * BP.y - AB.y * BP.x;
    double c2 = BC.x * CP.y - BC.y * CP.x;
    double c3 = CA.x * AP.y - CA.y * AP.x;

    if( ( c1 > 0 && c2 > 0 && c3 > 0 ) || ( c1 < 0 && c2 < 0 && c3 < 0 ) ) {
        //????§???¢????????´???????????????
        return 0;
    }

    //????§???¢????????´???????????????
    return 1;

}

int main(){
	
	Vertex2D A, B, C, P, Q;
	
	int n;
	
	cin >> n;
	
	for(int loop = 0; loop < n; loop++){
		cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y >> P.x >> P.y >> Q.x >> Q.y;
		if((hittest_point_polygon_2d(A, B, C, P) + hittest_point_polygon_2d(A, B, C, Q)) % 2 == 1){
			printf("OK\n");
		}else{
			printf("NG\n");
		}
	}
	
	return 0;
}