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>
#include<climits>
 
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;

  double ymx=-100000000,ymn=100000000;
  for(i=0;i<N+1;i++){
    ymx=max(ymx,p[i].y);
    ymn=min(ymn,p[i].y);
  }
  if(lt.a.y<=ymn||lt.a.y>=ymx)return 0;
  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 <iostream>
#include <cmath>
using namespace std;

struct Point{
  int x;
  int y;
}typedef point;

bool contain(point* p1, point* p2, point* p3, point* p);

int main(void){
  int n;
  cin>>n;
  int xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys;
  point p1,p2,p3,pk,ps;
  bool s,k;
  for(int i=0;i<n;i++){
    cin>>xp1>>yp1>>xp2>>yp2>>xp3>>yp3>>xk>>yk>>xs>>ys;
    p1.x=xp1;
    p1.y=yp1;
    p2.x=xp2;
    p2.y=yp2;
    p3.x=xp3;
    p3.y=yp3;
    pk.x=xk;
    pk.y=yk;
    ps.x=xs;
    ps.y=ys;
    s=contain(&p1,&p2,&p3,&ps);
    k=contain(&p1,&p2,&p3,&pk);
    if(s==k){
      cout<<"NG"<<endl;
    }
    else{
      cout<<"OK"<<endl;
    }
  }
  return 0;
}

bool contain(point* p1, point* p2, point* p3, point* p){
  int z1=0;
  int z2=0;
  z1+=(p1->x-p->x)*(p2->y-p->y)-(p2->x-p->x)*(p1->y-p->y);
  z2+=abs((p1->x-p->x)*(p2->y-p->y)-(p2->x-p->x)*(p1->y-p->y));
  z1+=(p2->x-p->x)*(p3->y-p->y)-(p3->x-p->x)*(p2->y-p->y);
  z2+=abs((p2->x-p->x)*(p3->y-p->y)-(p3->x-p->x)*(p2->y-p->y));
  z1+=(p3->x-p->x)*(p1->y-p->y)-(p1->x-p->x)*(p3->y-p->y);
  z2+=abs((p3->x-p->x)*(p1->y-p->y)-(p1->x-p->x)*(p3->y-p->y));
  if(abs(z1)==z2){
    return true;
  }
  else{
    return false;
  }
}

C++: #include <iostream>

using namespace std;

class Vector{
public:
	double x,y;

	Vector( double dx, double dy ) : x( dx ), y( dy ) {}
	Vector(){}

	Vector operator-( const Vector& lhs ){
		return Vector( x - lhs.x, y - lhs.y );
	}

	Vector& operator-=( const Vector& lhs ){
		x -= lhs.x;
		y -= lhs.y;
		return *this;
	}
};

double crossProduct( const Vector& rhs, const Vector& lhs ){
	return rhs.x * lhs.y - rhs.y * lhs.x;
}

bool line( Vector a, Vector b, Vector c ){
	b -= a;
	c -= a;

	double answer = crossProduct( b, c );

	if( answer < 0 ) return false;
	else if( answer > 0 ) return true;

	return false;
}

bool inTriangle( const Vector& a, const Vector& b, const Vector& c, const Vector& point ){
	bool answer[3];
	answer[0] = line( a, b, point );
	answer[1] = line( b, c, point );
	answer[2] = line( c, a, point );

	if( answer[0] == answer[1] && answer[1] == answer[2] ) return true;
	

	return false;
}



int main(int argc, char const* argv[])
{
	int n;
	Vector p1,p2,p3,k,s;

	cin >> n;
	for( int i = 0;i < n;i++ ){
		cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y >> k.x >> k.y >> s.x >> s.y;

		bool answer[2];
		answer[0] = inTriangle( p1, p2, p3, k );
		answer[1] = inTriangle( p1, p2, p3, s );

		if( answer[0] == answer[1] ) cout << "NG" << endl;
		else cout << "OK" << endl;
	}
	return 0;
}