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 <iostream>
#include <cmath>
#include <algorithm>
#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 P {
	double x, y;
	P() {}
	P(double x, double y) : x(x), y(y) {
	}
	P operator + (P p) {
		return P(add(x, p.x), add(y, p.y));
	}
	P operator - (P p) {
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator * (double d) {
		return P(x * d, y * d);
	}
	double dot(P p) {
		return add(x * p.x, y * p.y);
	}
	double det(P p) {
		return add(x * p.y, -y * p.x);
	}
};

bool cmp_x(const P& p, const P& q) {
	if (p.x != q.x) {
		return p.x < q.x;
	}
	return p.y < q.y;
}

vector<P> convex_hull(P* ps, int n) {
	sort(ps, ps + n, cmp_x);
	int k = 0;
	vector<P> qs(n * 2);

	for (int i = 0; i < n; i++) {
		while (k > 1 && (qs[k-1] - qs[k-2]).det(ps[i] - qs[k-1]) <= 0) {
			k--;
		}
		qs[k++] = ps[i];
	}
	for (int i = n-2, t = k; i >= 0; i--) {
		while (k > t && (qs[k-1] - qs[k-2]).det(ps[i] - qs[k-1]) <= 0) {
			k--;
		}
		qs[k++] = ps[i];
	}
	qs.resize(k-1);
	return qs;
}

P ps[10];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		P pp, qq;
		P psp[3];
		cin >> psp[0].x >> psp[0].y >> psp[1].x >> psp[1].y >> psp[2].x >> psp[2].y >> pp.x >> pp.y >> qq.x >> qq.y;
		for (int j = 0; j < 3; j++) {
			ps[j] = psp[j];
		}
		ps[3] = pp;
		vector<P> qs = convex_hull(ps, 4);
		bool hantei;
		if (qs.size() == 4) {
			hantei = false;
		} else {
			hantei = true;
			for (int j = 0; j < 3; j++) {
				if (qs[j].x == pp.x && qs[j].y == pp.y) {
					hantei = false;
					break;
				}
			}
		}
		for (int j = 0; j < 3; j++) {
			ps[j] = psp[j];
		}
		ps[3] = qq;
		qs = convex_hull(ps, 4);
		bool hantei2;
		if (qs.size() == 4) {
			hantei2 = false;
		} else {
			hantei2 = true;
			for (int j = 0; j < 3; j++) {
				if (qs[j].x == qq.x && qs[j].y == qq.y) {
					hantei2 = false;
					break;
				}
			}
		}
		if (hantei == hantei2) {
			cout << "NG" << endl;
		} else {
			cout << "OK" << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#define EPS 1e-10
using namespace std;

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

class Point
{
  public:
  double x,y;
  Point(double x = -1,double y = -1): x(x),y(y){}

  Point operator + (Point p ){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}//※イケメンに限る

  bool operator < (const Point& p) const
  {
    return x != p.x?x<p.x:y<p.y;
  }

  bool operator == (const Point& p)const
  {
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};

struct Segment
{
  Point p1,p2;
  Segment(Point p1 = Point(-1,-1),Point p2 = Point(-1,-1)):p1(p1),p2(p2){}
};
typedef Segment Line;
typedef vector<Point> Polygon;

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

double norm(Point a)
{
  return 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) > 0)return COUNTER_CLOCKWISE;
  if(cross(a,b) < 0)return CLOCKWISE;
  if(dot(a,b) < 0)return ONLINE_BACK;
  if(norm(a) < norm(b))return ONLINE_FRONT;
  return ON_SEGMENT;
}


bool isIntersect(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 );
}

bool isIntersect(Segment s1,Segment s2)
{
return isIntersect(s1.p1,s1.p2,s2.p1,s2.p2);
}


int main()
{
  int N;
  cin >> N;
  while(N-- > 0)
    {
      vector<Point> T(3);
      for(int i=0;i<3;i++)
	  cin >> T[i].x >> T[i].y;
      Segment s;
      cin >> s.p1.x >> s.p1.y >> s.p2.x >> s.p2.y;
      int cnt = 0;
      if(isIntersect(Segment(T[0],T[1]),s))cnt++;
      if(isIntersect(Segment(T[1],T[2]),s))cnt++;
      if(isIntersect(Segment(T[2],T[0]),s))cnt++;
      if(cnt == 1)
	cout << "OK" << endl;
      else
	cout << "NG" << endl;

    }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

typedef struct{
  int x,y;
}Point;

int det(Point p,Point q){
  return p.x*q.y-p.y*q.x;
}

int main(int argc, char const *argv[]) {
  int n;
  cin >>n;
  for(int T=0; T<n; ++T){
    int i;

    Point p[3],v,a;
    rep(i,3) scanf(" %d %d", &p[i].x, &p[i].y);
    scanf(" %d %d", &a.x, &a.y);
    scanf(" %d %d", &v.x, &v.y);

    bool _a=false, _v=false;
    int tmp=0;
    rep(i,3){
      Point t1,t2;
      t1.x=p[(i+1)%3].x-p[i].x;
      t1.y=p[(i+1)%3].y-p[i].y;
      t2.x=a.x-p[i].x;
      t2.y=a.y-p[i].y;

      if(det(t1,t2)>0) ++tmp;
      else --tmp;
    }
    if(tmp==3||tmp==-3) _a=true;

    tmp=0;
    rep(i,3){
      Point t1,t2;
      t1.x=p[(i+1)%3].x-p[i].x;
      t1.y=p[(i+1)%3].y-p[i].y;
      t2.x=v.x-p[i].x;
      t2.y=v.y-p[i].y;

      if(det(t1,t2)>0) ++tmp;
      else --tmp;
    }
    if(tmp==3||tmp==-3) _v=true;

    //cout << _a << " " << _v << endl;

    string s="OK";
    if(_a==_v) s="NG";
    std::cout << s << std::endl;
  }
  return 0;
}