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

 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 is_point_on_line(point a, point b, point c) {
  return (vec_abs(a-c) + vec_abs(c-b) < vec_abs(a-b) + EPS);
}

int inside(point p, point* ps, int n){
  segment t;
  t.a=t.b=p;
  t.b.x=INT_MAX;

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

  int cnt1=0,cnt2=0;
  for(int i=0;i<n;i++){
    if(is_point_on_line(t.a,t.b,ps[i])){
      cnt1++;
      continue;
    }
    if(is_intersected_ls(ps[i],ps[i+1],t.a,t.b))cnt2++;
  }
  return ((cnt1/2)+cnt2)%2;
}


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>
using namespace std;struct P{float x,y;int operator-=(P&a){x-=a.x;y-=a.y;}};P A,B,C,S,G;int X(P S){C.x=(B.y*S.x-B.x*S.y)/(A.x*B.y-A.y*B.x);C.y=(A.y*S.x-A.x*S.y)/(A.y*B.x-A.x*B.y);return C.x*C.y>0&&C.x+C.y<1;}main(){cin>>A.x;while(cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>S.x>>S.y>>G.x>>G.y){A-=C;B-=C;S-=C;G-=C;X(S)^X(G)?cout<<"OK":cout<<"NG";cout<<endl;}return 0;}

C++: #include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
using namespace std;

int main(void){
    int n;
    cin >> n;
    rep(i,n) {
        int count = 0;
        double x[5],y[5],a,b,c,d,p,q,det,ansx,ansy;
        //入力を多少簡略化
        for(int k=0;k<5;k++) {
            cin >> x[k] >> y[k];
        }
        rep(j,3) {
            //(x1,y1)(x2,y2)を結ぶax+by=p の係数
            if(j != 2) {
                a = y[j]-y[j+1];  b = x[j+1]-x[j];
                p = x[j+1]*y[j]-x[j]*y[j+1];
                //(x3,y3)(x4,y4)を結ぶcx+dy=q の係数
                c = y[3]-y[4];  d = x[4]-x[3];
                q = x[4]*y[3]-x[3]*y[4];
                //係数についての行列式
                det = a*d-c*b;
                //det=0で解は存在しない(この問題については２線分は同一直線上にないから
                if(fabs(det) > 0.00001){
                    ansx = (d*p - b*q)/det;
                    ansy = (-c*p + a*q)/det;
                    //ansxがどちらの線分のx座標範囲にも含まれるかを判定
                    if((x[j] - ansx)*(x[j+1] - ansx) <= 0.00001 && (x[3] - ansx)*(x[4] - ansx) <= 0.00001 ) {
                        count++;
                    }
                }
            } else {
                a = y[j]-y[0];  b = x[0]-x[j];
                p = x[0]*y[j]-x[j]*y[0];
                //(x3,y3)(x4,y4)を結ぶcx+dy=q の係数
                c = y[3]-y[4];  d = x[4]-x[3];
                q = x[4]*y[3]-x[3]*y[4];
                //係数についての行列式
                det = a*d-c*b;
                //det=0で解は存在しない(この問題については２線分は同一直線上にないから
                if(fabs(det) > 0.00001){
                    ansx = (d*p - b*q)/det;
                    ansy = (-c*p + a*q)/det;
                    //ansxがどちらの線分のx座標範囲にも含まれるかを判定
                    if((x[j] - ansx)*(x[0] - ansx) <= 0.00001 && (x[3] - ansx)*(x[4] - ansx) <= 0.00001 ) {
                        count++;
                    }
                }
            }
        }
        if(count == 1) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int get() { int r; cin >> r; return r; }
void solve() {
	double x[5], y[5], xs, ys, xt, yt;
	cin >> x[1] >> y[1] >> x[2] >> y[2] >> x[0] >> y[0] >> xs >> ys >> xt >> yt;
	int i1 = 1, i2 = 1, a = 1, b = 2, c = 0;
	for1(i, 3) {
		if (((x[a] - x[b]) * (ys - y[a]) - (y[a] - y[b]) * (xs - x[a])) * ((x[a] - x[b]) * (y[c] - y[a]) - (y[a] - y[b]) * (x[c] - x[a])) < 0)i1 = 0;
		if (((x[a] - x[b]) * (yt - y[a]) - (y[a] - y[b]) * (xt - x[a])) * ((x[a] - x[b]) * (y[c] - y[a]) - (y[a] - y[b]) * (x[c] - x[a])) < 0)i2 = 0;
		a++; b++; c++;
		if (a >= 3)a %= 3;
		if (b >= 3)b %= 3;
		if (c >= 3)c %= 3;
	}
	cout << (i1 + i2 == 1 ? "OK\n" : "NG\n");
}
signed main() {
	int n; cin >> n; for1(i, n)solve();
}

C++: #include <iostream>
#include <cmath>
using namespace std;

struct Vec2d{
  double x,y;
};

double cross(Vec2d &A, Vec2d &B){
  return A.x*B.y - A.y*B.x;
}

int main(void){
	int n;cin>>n;
  while(n--){
  	double x1,y1,x2,y2,x3,y3,xk,yk,xs,ys;
  	cin>>x1>>y1>>x2>>y2>>x3>>y3>>xk>>yk>>xs>>ys;
    Vec2d AB,BC,CA,AK,BK,CK,AS,BS,CS;
    AB.x = x2-x1; AB.y = y2-y1;
    BC.x = x3-x2; BC.y = y3-y2;
    CA.x = x1-x3; CA.y = y1-y3;
    AK.x = xk-x1; AK.y = yk-y1;
    BK.x = xk-x2; BK.y = yk-y2;
    CK.x = xk-x3; CK.y = yk-y3;
    AS.x = xs-x1; AS.y = ys-y1;
    BS.x = xs-x2; BS.y = ys-y2;
    CS.x = xs-x3; CS.y = ys-y3;
    bool k=true,s=true;
    if(cross(AB,AK)>0.0 && cross(BC,BK)>0.0 && cross(CA,CK)>0.0)
    k=false;
    else if(cross(AB,AK)<0.0 && cross(BC,BK)<0.0 && cross(CA,CK)<0.0)
    k=false;
    else ;
    if(cross(AB,AS)>0.0 && cross(BC,BS)>0.0 && cross(CA,CS)>0.0)
    s=false;
    else if(cross(AB,AS)<0.0 && cross(BC,BS)<0.0 && cross(CA,CS)<0.0)
    s=false;
    else ;
    
    if(s!=k) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
    
  }
  return 0;
}