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 <cstdio>
#include <cmath>
#define EPS 1e-10
struct vektor{
	double x,y;
	vektor(){}
	vektor(double xx,double yy){
		x=xx;
		y=yy;
	}
	double add(double a,double b){
		if(fabs(a+b)<EPS*(fabs(a)+fabs(b)))return 0;
		return a+b;
	}
	vektor operator +(vektor v){
		return vektor(x+v.x,y+v.y);
	}

	vektor operator -(vektor v){
		return vektor(x-v.x,y-v.y);
	}
	vektor operator *(double d){
		return vektor(x*d,y*d);
	}
	double dot(vektor v){
		return add(x*v.x,y*v.y);
	}
	double det(vektor v){
		return add(x*v.y,-y*v.x);
	}
};

bool on_seg(vektor p1,vektor p2,vektor q){
	return fabs((p1-q).det(p2-q))==0 && (p1-q).dot(p2-q)<=0;
}
vektor intersection(vektor p1,vektor p2,vektor q1,vektor q2){
	return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));
}

int n;
vektor vek[5];

bool check(){
	vektor v[5];
	for(int i=1;i<=4;i++){
		v[i]=vek[i]-vek[0];
	}
	double s=(v[3].x*v[2].y-v[3].y*v[2].x)/(v[1].x*v[2].y-v[1].y*v[2].x);
	double t=(v[3].x*v[1].y-v[3].y*v[1].x)/(v[1].y*v[2].x-v[1].x*v[2].y);
	int data3,data4;
	if(s>0 && t>0 && s+t<1)data3=1;
	else data3=-1;
	s=(v[4].x*v[2].y-v[4].y*v[2].x)/(v[1].x*v[2].y-v[1].y*v[2].x);
	t=(v[4].x*v[1].y-v[4].y*v[1].x)/(v[1].y*v[2].x-v[1].x*v[2].y);
	if(s>0 && t>0 && s+t<1)data4=1;
	else data4=-1;
	return data3*data4<0;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<5;j++){
			scanf("%lf %lf",&vek[j].x,&vek[j].y);
		}
		bool flag=check();
		printf("%s\n",flag?"OK":"NG");
	}
	return 0;
}

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

bool cross_p(int x1, int y1, int x2, int y2, int xp, int yp){
	if((x2-x1)*(yp-y1) < (y2-y1)*(xp-x1))
		return true;
	else
		return false;
}

int main(){

	int n;
	cin>>n;

	for(int i=0;i<n;i++){
		int x1, y1, x2, y2, x3, y3, xk, yk, xs, ys;
		bool altair, vega;

		cin>>x1>>y1>>x2>>y2>>x3>>y3>>xk>>yk>>xs>>ys;

		if((cross_p(x1, y1, x2, y2, xk, yk) == cross_p(x2, y2, x3, y3, xk, yk)) && (cross_p(x2, y2, x3, y3, xk, yk) == cross_p(x3, y3, x1, y1, xk, yk)))
			altair = true;
		else
			altair = false;

		if((cross_p(x1, y1, x2, y2, xs, ys) == cross_p(x2, y2, x3, y3, xs, ys)) && (cross_p(x2, y2, x3, y3, xs, ys) == cross_p(x3, y3, x1, y1, xs, ys)))
			vega = true;
		else
			vega = false;

		if(altair != vega)
			cout<<"OK"<<endl;
		else
			cout<<"NG"<<endl;
	}

	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
#define INF 0x7FFFFFFF
const double EPS = 1e-10;


inline bool eq(double a, double b) { return fabs(b - a) < EPS;}

struct p_t{
  double x;
  double y;
  double norm() { return x * x + y * y; }
  double abs() { return sqrt(norm()); }
};
struct l_t{
	p_t a, b;
};

double cross(p_t p,p_t q);
p_t line(p_t p,p_t q);

bool asc(p_t left,p_t right) {
    return left.x == right.x ? left.y < right.y : left.x < right.x;
}
int Crosspoint(l_t l,l_t m);

int main(){
  int n;
  cin>>n;
  for(int t=0;t<n;t++){
    p_t p,q,r,k,s;
    cin>>p.x>>p.y>>q.x>>q.y>>r.x>>r.y>>k.x>>k.y>>s.x>>s.y;
    l_t pq,qr,rp,ks;
    pq.a=p;
    pq.b=q;
    qr.a=q;
    qr.b=r;
    rp.a=r;
    rp.b=p;
    ks.a=k;
    ks.b=s;
    int ans=0;
    ans+=Crosspoint(pq,ks);
    ans+=Crosspoint(qr,ks);
    ans+=Crosspoint(rp,ks);
    if(ans==1){
      cout<<"OK"<<endl;
    }
    else{
      cout<<"NG"<<endl;
    }
  }
}


p_t line(p_t p,p_t q){
  p_t z;
  z.x=q.x-p.x;
  z.y=q.y-p.y;
  return z;
}


double cross(p_t p,p_t q){
  return p.x*q.y-p.y*q.x;
}

int Crosspoint(l_t l,l_t m){
  p_t aa,bb,cc,dd;
  aa.x=l.b.x-l.a.x;
  aa.y=l.b.y-l.a.y;
  bb.x=m.b.x-m.a.x;
  bb.y=m.b.y-m.a.y;
  cc=aa;
  dd.x=l.b.x-m.a.x;
  dd.y=l.b.y-m.a.y;
	double A = cross(aa,bb);
	double B = cross(cc,dd);
	//if (abs(A) < EPS && abs(B) < EPS) return 0;
  if(B/A>0&&B/A<1) return 1;
  return 0;
}

C++: #include <iostream>
#include <cmath>

using namespace std;

struct Point {
	double x, y;
	Point(double x=0, double y=0) : x(x), y(y) {}
	Point operator-(const Point &o) const {
		return Point(x-o.x, y-o.y);
	}
};

double cross(Point &a, Point &b) {
	return (a.x * b.y - b.x * a.y);
}

bool in(Point &a, Point &b, Point &c, Point &p) {
	Point ab = b-a;
	Point bc = c-b;
	Point ca = a-c;
	Point ap = p-a;
	Point bp = p-b;
	Point cp = p-c;
	double cross_a = cross(ab, ap);
	double cross_b = cross(bc, bp);
	double cross_c = cross(ca, cp);
	return (cross_a / abs(cross_a) == cross_b / abs(cross_b) &&
			cross_b / abs(cross_b) == cross_c / abs(cross_c));
}



int main() {
	int n; cin >> n;
	while (n--) {
		Point v[3], altair, vega;
		for (int i = 0; i < 3; i++) cin >> v[i].x >> v[i].y;
		cin >> altair.x >> altair.y >> vega.x >> vega.y;

		bool altair_in, vega_in;
		altair_in = in(v[0], v[1], v[2], altair);
		vega_in = in(v[0], v[1], v[2], vega);

		if (altair_in ^ vega_in) 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");
	}
}