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 0
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]))<0){
			cout<<"OK\n";
		}
		else{
			cout<<"NG\n";
		}
	}
}



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

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <vector>

#define rep2(i, b, n) for(int i=b; i < n; ++i)
#define repm(i, b, n) for(int i=b; i > n; --i)
#define rep(i, n) rep2(i, 0, n)

using namespace std;

int cross_product( int x1, int y1, int x2, int y2 )
{
	return ((x1 * y2) - (x2 * y1));
}

int main( void )
{
	int n;
	
	while (cin >> n)
	{
		for (int i=0; i < n; ++i)
		{
			int x1, y1, x2, y2, x3, y3, xk, yk, xs, ys;
			cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3
				>> xk >> yk >> xs >> ys;
			
			int v1, v2, v3, v4, v5, v6;
		
			v1 = cross_product((x2-x1), (y2-y1), (xk-x1), (yk-y1));
			v2 = cross_product((x3-x2), (y3-y2), (xk-x2), (yk-y2));
			v3 = cross_product((x1-x3), (y1-y3), (xk-x3), (yk-y3));
		
			v4 = cross_product((x2-x1), (y2-y1), (xs-x1), (ys-y1));
			v5 = cross_product((x3-x2), (y3-y2), (xs-x2), (ys-y2));
			v6 = cross_product((x1-x3), (y1-y3), (xs-x3), (ys-y3));
			if (((v1 > 0) && (v2 > 0) && (v3 > 0) &&
				((v4 < 0) || (v5 < 0) || (v6 < 0))) ||
				((v4 > 0) && (v5 > 0) && (v6 > 0) &&
				((v1 < 0) || (v2 < 0) || (v3 < 0))) ||
				((v1 < 0) && (v2 < 0) && (v3 < 0) &&
				((v4 > 0) || (v5 > 0) || (v6 > 0))) ||
				((v4 < 0) && (v5 < 0) && (v6 < 0) &&
				((v1 > 0) || (v2 > 0) || (v3 > 0))) 
				)
			{
				cout << "OK" << endl;
			}
			else
			{
				cout << "NG" << endl;
			}
		}
	}
	
	return 0;
}

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

class Vector2
{
public:
	Vector2() : x( 0 ), y( 0 ){}
	Vector2( int _x, int _y ) : x( _x ), y( _y ){}
	Vector2& operator=( const Vector2& v )
	{
		this->x = v.x;
		this->y = v.y;
		return *this;
	}
	Vector2 operator-( const Vector2& v )
	{
		Vector2 ret;
		ret.x = this->x - v.x;
		ret.y = this->y - v.y;
		return ret;
	}
	int clossProduct( const Vector2& v )
	{
		return this->x * v.y - this->y * v.x;
	}

	int x, y;
};

bool solve()
{
	Vector2 coodi[ 5 ];
	for( int i = 0; i < 5; ++i ){
		Vector2 v;
		cin >> v.x >> v.y;
		coodi[ i ] = v;
	}
	int closs[ 2 ][ 3 ];
	for( int i = 0; i < 2; ++i ){
		Vector2& o = coodi[ 3 + i ];
		for( int j = 0; j < 3; ++j ){
			Vector2 v = coodi[ ( j + 1 ) % 3 ] - coodi[ j ];
			Vector2 w = o - coodi[ j ];
			closs[ i ][ j ] = v.clossProduct( w );
		}
	}
	for( int i = 0; i < 2; ++i ){
		int a = closs[ i ][ 0 ] * closs[ i ][ 1 ];
		int b = closs[ i ][ 1 ] * closs[ i ][ 2 ];
		int c = closs[ i ][ 2 ] * closs[ i ][ 0 ];
		closs[ i ][ 0 ] = a;
		closs[ i ][ 1 ] = b;
		closs[ i ][ 2 ] = c;
	}
	if( ( ( closs[ 0 ][ 0 ] > 0 && closs[ 0 ][ 1 ] > 0 && closs[ 0 ][ 2 ] > 0 )
		&& ( closs[ 1 ][ 0 ] < 0 || closs[ 1 ][ 1 ] < 0 || closs[ 1 ][ 2 ] < 0 ) )
		|| ( ( closs[ 0 ][ 0 ] < 0 || closs[ 0 ][ 1 ] < 0 || closs[ 0 ][ 2 ] < 0 )
		&& ( closs[ 1 ][ 0 ] > 0 && closs[ 1 ][ 1 ] > 0 && closs[ 1 ][ 2 ] > 0 ) ) ){
		return true;
	}
	return false;
}

int main()
{
	int n;
	while( cin >> n ){
		for( int i = 0; i < n; ++i ){
			if( solve() ){
				cout << "OK" << endl;
			}else{
				cout << "NG" << endl;
			}
		}
	}

	return 0;
}