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<algorithm>
using namespace std;
int x[3],y[3];
int isin(int px,int py){
	bool ok=true;
		for(int i=0;i<3;i++){
			bool plus=false;
			if(x[(i+1)%3]==x[(i+2)%3]){
				if(x[i]>x[(i+1)%3])plus=true;
			}
			else{
				int a,b;
				a=(x[i]-x[(i+1)%3])*(y[(i+2)%3]-y[(i+1)%3]);
				b=(y[i]-y[(i+1)%3])*(x[(i+2)%3]-x[(i+1)%3]);
				if(a>b)plus=true;
			}
			bool pnt=false;
			if(x[(i+1)%3]==x[(i+2)%3]){
				if(px>x[(i+1)%3])pnt=true;
			}
			else{
				int a,b;
				a=(px-x[(i+1)%3])*(y[(i+2)%3]-y[(i+1)%3]);
				b=(py-y[(i+1)%3])*(x[(i+2)%3]-x[(i+1)%3]);
				if(a>b)pnt=true;
			}
			if(pnt!=plus)ok=false;
		}
		if(ok)return 1;
		else return 0;
}
int main(){
	int n;
	cin>>n;
	for(int u=0;u<n;u++){
	for(int i=0;i<3;i++)cin>>x[i]>>y[i];
	int px,py,gx,gy;
	cin>>px>>py>>gx>>gy;
	if(isin(px,py)==isin(gx,gy))cout<<"NG"<<endl;
	else cout<<"OK"<<endl;
	}
	return 0;
}

C++: #include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
 
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 );
}

int is_point_on_line(point a, point b, point c) {
  return cross(b-a, c-a)==0.0 &&
         (dot(b-a, c-a) > -EPS) &&
         (dot(a-b, c-b) > -EPS);
}

int inside(point p, vector<point> ps){
  point a,b;
  a=b=p;

  b.x=1000000;

  double ymx=-DBL_MAX,ymn=DBL_MAX;
  for(int i=0;i<ps.size();i++){
    ymx=max(ymx,ps[i].y);
    ymn=min(ymn,ps[i].y);
  }
  if(a.y<=ymn||a.y>=ymx)return 0;

  int cnt1=0;
  for(int i=0;i<ps.size();i++)
    if(is_point_on_line(a,b,ps[i]))cnt1++;
  
  int cnt=0;
  for(int i=0;i<ps.size();i++)
    if(is_intersected_ls(ps[i],ps[(i+1)%ps.size()],a,b))cnt++;

  return (cnt-cnt1)%2;
}

int main(void){
  int n;
  point k,s,in;
  vector<point>p; 

  cin >> n;
  while(n--){
    p.clear();
    for(int i=0;i<3;i++){
      cin >> in.x >> in.y;
      p.push_back(in);
    }     

    cin >> k.x >> k.y >> s.x >> s.y;

    if(inside(k,p)!=inside(s,p))cout << "OK" << endl;
    else cout << "NG" << endl;
     
  }
 
  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);
  }
};

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

  return 0;
}

C++: #include <bits/stdc++.h>

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;
typedef complex<double> P;
const double EPS = 1e-8;
const double INF = 1e12;
namespace std {
  bool operator<(const P& a, const P& b){
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b){ return imag(conj(a) * b); }
double dot(const P& a, const P& b){ return real(conj(a) * b); }
typedef vector<P> G;

#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
enum { OUT, ON, IN };

int contains(const G& x, const P& y){
  bool in_ = false;
  rep(i, x.size()){
    P a = curr(x, i) - y, b = next(x, i) - y;
    if (imag(a) > imag(b)) swap(a, b);
    if (imag(a) <= 0 && 0 < imag(b)){
      if (cross(a, b) < 0) in_ = !in_;
    }
    if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;
  }
  return in_ ? IN : OUT;
}

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }


int main()
{
  rep(i, in()){
    G area;
    rep(j, 3){
      int x, y;
      x = in();
      y = in();
      area.push_back(P(x, y));
    }
    int x, y;
    x = in();
    y = in();
    P k(x, y);
    x = in();
    y = in();
    P s(x, y);
    if (contains(area, k) != contains(area, s)){
      puts("OK");
    }
    else {
      puts("NG");
    }
  }
  return 0;
}