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 <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 static_cast<double>( this->x ) * v.y > static_cast<double>( this->y ) * v.x
			? 1 : -1;
	}

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

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <cmath>
#include <algorithm>
using namespace std;

// * XYテ・ツコツァテヲツィツ?
#define X real()
#define Y imag()

// * テァツつケテ」ツ?ョティツ。ツィテァツ渉セ
typedef complex<double> P;

// * ティツィツアテ・ツョツケテ」ツ?凖」ツつ凝ィツェツ、テ・ツキツョテ篠オ
const double EPS = 1e-10;
// * Infinity
const double INF = 1e12;
// * テ・ツ??・ツ堕ィテァツ篠?
const double PI = acos(-1.0);
// * Infinity 2
const P INF_P(INF,INF);

// * complex<double> テ」ツ?ョテゥツ??・ツコツ湘」ツつ津・ツョツ堙ァツセツゥテ」ツ?凖」ツつ?
namespace std {
	bool operator < (const P& a, const P& b) {
		return (real(a) != real(b))? real(a) < real(b) : imag(a) < imag(b);
	}
}

// * 2テ、ツケツ療」ツ?凖」ツつ?
double sq(double x) {
	return x * x;
}

// * 2テァツつケテゥツ鳴禿」ツ?ョティツキツ敕ゥツ崢「
double dist(P p1, P p2) {
	return abs(p1 - p2);
}

// * 2テ」ツ?、テ」ツ?ョテ」ツつケテ」ツつォテ」ツδゥテ」ツδシテ」ツ?古ァツュツ嘉」ツ?療」ツ??」ツ?凝」ツ?ゥテ」ツ??」ツ??
bool equal(double a, double b) {
	return ( fabs( a - b ) < EPS );
}
// * 2テ」ツ?、テ」ツ?ョテ」ツδ凖」ツつッテ」ツδ暗」ツδォテ」ツ?古ァツュツ嘉」ツ?療」ツ??」ツ?凝」ツ?ゥテ」ツ??」ツ??
bool eq_v(P a, P b) {
	return ( equal( a.X, b.X ) && equal( a.Y, b.Y ) );
}

// * テ・ツ??ァツゥツ?(dot product) : aテ」ツδサb = |a||b|cosテ篠?
double dot(P a, P b) {
	return real( conj(a) * b );
}

// * テ・ツ、ツ姪ァツゥツ?(cross product) : aテδ傭 = |a||b|sinテ篠?
double cross(P a, P b) {
	return imag( conj(a) * b ) ;
}

// テァツキツ堙・ツ按?」ツ?ョティツ。ツィテァツ渉セ
struct Segment{
	// テァツつケ a, b テ」ツつ津ァツォツッテァツつケテ」ツ?ィテ」ツ?凖」ツつ凝ァツキツ堙・ツ按?
	P a, b;
	// テ」ツつウテ」ツδウテ」ツつケテ」ツδ暗」ツδゥテ」ツつッテ」ツつソテ」ツ?ァテ・ツ按敕ヲツ慊淌・ツ個?
	Segment(P a_, P b_) {
		a = a_; b = b_;
	}
	// テァツつケ p テ」ツ?古ァツキツ堙・ツ按?、ツクツ甘」ツ?ォテ」ツ?づ」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ??
	bool contain(P p) { return (abs(a-p) + abs(p-b) < abs(a-b) + EPS); }
};
// Segment テ」ツ?ョテゥツ??・ツコツ湘」ツつ津・ツョツ堙ァツセツゥ (xテ・ツコツァテヲツィツ凖」ツ?ョテ・ツーツ湘」ツ?陛」ツ??ァツォツッテァツつケテ」ツ?ァテヲツッツ氾ィツシツ?
bool operator < (const Segment& s1, const Segment& s2) { return s1.a < s2.a; }

// テ、ツクツ嘉ィツァツ津・ツスツ「テ」ツ?ョティツ。ツィテァツ渉セ
struct Triangle{
private:
	// テ、ツスツ凖・ツシツヲテ・ツョツ堙ァツ青?」ツ?凝」ツつ?3 テ」ツ?、テ」ツ?ョティツァツ津」ツ?ョティツァツ津・ツコツヲテ」ツつ津ヲツアツづ」ツつ?」ツつ?(テ・ツ??ゥツδィテ」ツ?ョテゥツ鳴「テヲツ閉ーテ」ツ?ァテ、ツスツソテァツ板ィ)
    double law_of_cos(double a, double b, double c) {
        return acos( (b*b + c*c - a*a) / (2.0 * b * c) );
    }
public:
	// 3 テ」ツ?、テ」ツ?ョテゥツ?づァツつケ
	P a, b, c;
    // 3 テ」ツ?、テ」ツ?ョティツセツコテ」ツ?ョテゥツ閉キテ」ツ??
    double edgeA, edgeB, edgeC;
    // 3 テ」ツ?、テ」ツ?ョティツァツ津」ツ?ョティツァツ津・ツコツヲ (テ」ツδゥテ」ツつクテ」ツつ「テ」ツδウ)
    double angleA,angleB,angleC;
    
    // テ」ツつウテ」ツδウテ」ツつケテ」ツδ暗」ツδゥテ」ツつッテ」ツつソテ」ツ?ァテ・ツ按敕ヲツ慊淌・ツ個?
    Triangle(P p1, P p2, P p3) {
        a = p1;
        b = p2;
        c = p3;
        edgeB = abs(c-a);
        edgeA = abs(b-c);
        edgeC = abs(a-b);
        angleA = law_of_cos( edgeA, edgeB, edgeC );
        angleB = law_of_cos( edgeB, edgeC, edgeA );
        angleC = law_of_cos( edgeC, edgeA, edgeB );
    }
	// テァツつケ p テ」ツ?古、ツクツ嘉ィツァツ津・ツスツ「テ」ツ?ョティツセツコテ、ツクツ甘」ツ?ォテ」ツ?づ」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ??
	/*bool on_boundary(P p) {
		Segment AB(a,b), BC(b,c), CA(c,a);
		return (AB.contain( p ) || BC.contain( p ) || CA.contain( p ) );
	}*/
	// テァツつケ p テ」ツ?古、ツクツ嘉ィツァツ津・ツスツ「テ」ツ?ョテ・ツ??ゥツδィテ」ツ?ォテ」ツ?づ」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ??( AOJ 0012 テ」ツ?ァテヲツ、ツ愿ィツィツシテヲツクツ暗」ツ?ソ )
	// テァツつケ p テ」ツ?古、ツクツ嘉ィツァツ津・ツスツ「テ」ツ?ョティツセツコテ、ツクツ?or テゥツ?づァツつケテ、ツクツ?テ」ツ?ォテ」ツ?づ」ツつ凝」ツ?ィテ」ツ?催」ツ?ッティツェツ、テ・ツキツョテ」ツ?ァテヲツュツ」テ」ツ?療」ツ??ァツオツ静ヲツ楪愿」ツ?古ィツソツ氾」ツ?」テ」ツ?ヲテ」ツ?禿」ツ?ェテ」ツ??」ツ?ョテ」ツ?ァテヲツウツィテヲツ??!!
	bool is_inside(P p) {
		// ティツセツコテ、ツクツ甘」ツ?ォテ」ツ?づ」ツつ凝」ツ?ィテ」ツ??
		//if( this->on_boundary(p) ) return true;
		
		Triangle t1( a , b , p );
		Triangle t2( b , c , p );
		Triangle t3( c , a , p );
		// ティツァツ但PB + ティツァツ達PB + ティツァツ辰PA テ」ツ??360テ・ツコツヲテ」ツ?ェテ」ツつ?テァツつケ p テ」ツ?ッテ、ツクツ嘉ィツァツ津・ツスツ「テ」ツ?ョテ・ツ??ゥツδィテ」ツ?ォテ」ツ?づ」ツつ?
		return equal( t1.angleC + t2.angleC + t3.angleC , 2.0*PI );
	}
};

int main(){
	int n;
	cin >> n;
	for(int i=0 ; i < n ; i++ ){
		int xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
		cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
		P p1(xp1,yp1), p2(xp2,yp2), p3(xp3,yp3), K(xk,yk), S(xs,ys);
		Triangle t( p1 , p2, p3 );
		int a = t.is_inside(K)? 1 : 0 ;
		int b = t.is_inside(S)?	1 : 0 ;
		cout << ((a^b)? "OK" : "NG") << endl;
	}
}