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<vector>
#include<complex>
#include<cassert>
#include<iostream>
#include<algorithm>
using namespace std;

const double eps = 1e-8;
const double inf = 1e12;

typedef complex<double> P; //Point

namespace std {
  bool operator<(const P &a, const P &b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

struct L {  //Line
  P s,t;
L(const P a,const P b) : s(a), t(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);
}

int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if( cross(b, c) > 0 ) return +1; // counter clockwise
  if( cross(b, c) < 0 ) return -1; // clockwise
  if( dot(b, c) < 0 ) return +2;   // c--a--b on line
  if( norm(b) < norm(c) ) return -2; // a--b--c on line
  return 0;
}

bool intersectSS(const L &s, const L &t) {
    return ccw(s.s,s.t,t.s) * ccw(s.s,s.t,t.t) <= 0 &&
        ccw(t.s,t.t,s.s) * ccw(t.s,t.t,s.t) <= 0;
}

int main() {
    int n,x,y;
    cin>>n;
    while(n--) {
        P tri[3];
        for(int i=0; i<3; ++i) {
            cin>>x>>y;
            tri[i] = P(x,y);
        }
        cin>>x>>y;
        P f(x,y);
        cin>>x>>y;
        P m(x,y);
        L fm(f,m);
        vector<L> tril;
        for(int i=0; i<3; ++i) tril.push_back(L(tri[i],tri[(i+1)%3]));

        int cc = 0;
        for(int i=0; i<3; ++i)
            if(intersectSS(fm, tril[i])) cc++;

        if(cc%2) cout<<"OK"<<endl;
        else cout<<"NG"<<endl;
    }
}

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)&&Crosspoint(ks,pq));
    ans+=(Crosspoint(qr,ks)&&Crosspoint(ks,qr));
    ans+=(Crosspoint(rp,ks)&&Crosspoint(ks,rp));
    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 <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it,c) for(__typeof((c).begin())it=(c).begin(); it!=(c).end();++it)
#define RFOR(it,c) for(__typeof((c).rbegin())it=(c).rbegin(); it!=(c).rend();++it)
#define exist(c, v) (find((c).begin(), (c).end(), (v)) != (c).end())

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
	return os;
}

const double EPS = 1e-9;

struct point {
	double x, y;
	point():x(0), y(0) {}
	point(double x, double y):x(x), y(y) {}
	point(const point& p):x(p.x), y(p.y) {}

	point operator+ (const point& p) const {
		return point(x + p.x, y + p.y);
	}

	point operator- (const point& p) const {
		return point(x - p.x, y - p.y);
	}

	point operator* (const double s) const {
		return point(x * s, y * s);
	}

	point operator* (const point& p) const {
		return point(x * p.x - y * p.y, x * p.y + y * p.x);
	}

	point operator/ (const double s) const {
		return point(x / s, y / s);
	}

	bool operator< (const point& p) const {
		return x + EPS < p.x || abs(x - p.x) < EPS && y + EPS < p.y;
	}

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

inline double abs(const point& p) {
	return sqrt(p.x * p.x + p.y * p.y);
}

inline double norm(const point& p) {
	return p.x * p.x + p.y * p.y;
}

inline double dot(const point& l, const point& r) {
	return l.x * r.x + l.y * r.y;
}

inline double cross(const point& l, const point& r) {
	return l.x * r.y - l.y * r.x;
}

typedef vector<point> polygon;

inline int ccw(const point& a, point b, point c) {
	b = b - a;
	c = c - a;
	const double tmp = cross(b, c);
	if(tmp > EPS) return 1; // ccw
	if(tmp < -EPS) return -1; // cw
	if(dot(b, c) < 0) return 2; // c, a, b 順に一直線上
	if(norm(b) < norm(c)) return -2; // a, b, c 順に一直線上
	return 0; //a, c, b 順で一直線上
}

bool contain(const polygon& p, const point& a) {
	const int d1 = ccw(a, p[0], p[1]), d2 = ccw(a, p[1], p[2]), d3 = ccw(a, p[2], p[0]);
	return !(d1 * d2 == -1 || d2 * d3 == -1 || d3 * d1 == -1);
}

int main() {
	int n;
	scanf("%d", &n);

	while(n--) {
		int x1, y1, x2, y2, x3, y3, xk, yk, xs, ys;
		scanf("%d %d %d %d %d %d", &x1, &y1, &x2, &y2, &x3, &y3);
		polygon triangle;
		triangle.push_back(point(x1, y1));
		triangle.push_back(point(x2, y2));
		triangle.push_back(point(x3, y3));

		scanf("%d %d %d %d", &xk, &yk, &xs, &ys);
		if(contain(triangle, point(xk, yk)) != contain(triangle, point(xs, ys)))
			puts("OK");
		else
			puts("NG");
	}


	return EXIT_SUCCESS;
}