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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
typedef complex<double> P;
typedef const P &rP;
typedef pair<P,P> seg;
vector<P> tri(3);
vector<P> aa(2);
double dot(rP a, rP b){
    return real(a) * real(b) + imag(a) * imag(b);
}
int check(P r){
	P a=tri[0]-tri[1],ar=r-tri[0];
	P b=tri[1]-tri[2],br=r-tri[1];
	P c=tri[2]-tri[0],cr=r-tri[2];
	double A=dot(ar,a),B=dot(br,b),C=dot(cr,c);
	if(A>EPS&&B>EPS&&C>EPS) return 1;
	if(A<-EPS&&B<-EPS&&C<-EPS) return 1;
	return -1;
}
void mainmain(){
	int n;
	cin>>n;
	rep(i,n){
		rep(j,3){
			double a,b;
			cin>>a>>b;
			tri[j]=P(a,b);
		}
		rep(j,2){
			double a,b;
			cin>>a>>b;
			aa[j]=P(a,b);	
		}
		if(check(aa[0])*(check(aa[1]))<-EPS){
			cout<<"OK\n";
		}
		else{
			cout<<"NG\n";
		}
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

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

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


//時計回りに辺を構築する。
vector<segment> construct_edge(point* p, int n){
  vector<segment>seg,seg2;
  segment temp;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i!=j){
	temp.a=p[i];
	temp.b=p[j];
	seg.push_back(temp);
      }
    }
  }

  int t=seg.size();
  for(int i=0;i<t;i++){
    int fg=0;
    for(int j=0;j<t;j++){
      if(i!=j && seg[i].b.x==seg[j].a.x && seg[i].b.y==seg[j].a.y){
	if(ccw(seg[i].a,seg[i].b,seg[j].b)==1){
	  fg=1;
	  break;
	}
      }
    }
    if(!fg)seg2.push_back(seg[i]);
  }
  return seg2;
}
/*
点と多角形の内外判定

ps 多角形の辺
p  点
n  多角形の辺の数

点が多角形に含まれれば1,
そうでなければ0を返す。
*/
int point_contain(vector<segment> ps, point p, int n){
  point q;
  q.x=100000000;
  q.y=p.y;
  int cnt=0;
  for(int i=0;i<n;i++){
    cnt+=is_intersected_ls(ps[i].a,ps[i].b,p,q);
  }
  return cnt%2;
}

int main(void){
  int n;
  point p[3],k,s;
  vector<segment>seg;

  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;

    seg=construct_edge(p,3);

    if(point_contain(seg,k,3)!=point_contain(seg,s,3))cout << "OK" << endl;
    else cout << "NG" << endl;
    
  }

  return 0;
}

C++: #include<stdio.h>
int main(){
    int a;
    scanf("%d",&a);
    while(a--){
        int ax,bx,cx,dx,ex;
        int ay,by,cy,dy,ey;
        scanf("%d%d%d%d%d%d%d%d%d%d",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy,&ex,&ey);
        int count=0;
        int p=(dx-ax)*(by-ay)-(dy-ay)*(bx-ax);
        int q=(dx-bx)*(cy-by)-(dy-by)*(cx-bx);
        int r=(dx-cx)*(ay-cy)-(dy-cy)*(ax-cx);
        if(p>=0&&q>=0&&r>=0)count++;
        else if(p<=0&&q<=0&&r<=0)count++;
        p=(ex-ax)*(by-ay)-(ey-ay)*(bx-ax);
        q=(ex-bx)*(cy-by)-(ey-by)*(cx-bx);
        r=(ex-cx)*(ay-cy)-(ey-cy)*(ax-cx);
        if(p>=0&&q>=0&&r>=0)count++;
        else if(p<=0&&q<=0&&r<=0)count++;
        if(count==1)printf("OK\n");
        else printf("NG\n");
    }
}