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<stdio.h>
#include<iostream>
#include<cmath>
#include<vector>

#define SAME_SIGN( a , b ) ( a * b > 0 ? true : false )

namespace geometry{

#define EPS 1E-10

	struct point{
		double x;
		double y;
		point(){}
		point( double x , double y ):x(x),y(y){}
		point& operator += ( const point& p ){ x += p.x; y += p.y; return *this; }
		point& operator -= ( const point& p ){ x -= p.x; y -= p.y; return *this; }
		point& operator *= ( double factor ){ x *= factor; y *= factor; return *this; }
		point& operator /= ( double factor ){ x /= factor; y /= factor; return *this; }
		bool operator == ( const point& p ) const { return (std::abs(x - p.x) < EPS && std::abs(y - p.y) < EPS); }
		bool operator != ( const point& p ) const { return !(*this == p); }
		double norm() const{ return sqrt( pow( x , 2) + pow( y , 2 ) ); }
	};

	typedef point vector2d;

	struct triangle{
		point a;
		point b;
		point c;
		triangle(){}
		triangle( point a , point b , point c ):a(a),b(b),c(c){}
	};

	point operator + ( const point& p1 , const point& p2 ){
		point p(p1);
		p += p2;
		return p;
	}
	point operator - ( const point& p1 , const point& p2 ){
		point p(p1);
		p -= p2;
		return p;
	}
	point operator * ( const point& p1 , double factor ){
		point p(p1);
		p *= factor;
		return p;
	}
	point operator * ( double factor , const point& p1 ){
		point p(p1);
		p *= factor;
		return p;
	}
	point operator / ( const point& p1 , double factor ){
		point p(p1);
		p /= factor;
		return p;
	}
	std::istream& operator >> ( std::istream& s , point& p ){
		return s >> p.x >> p.y;
	}

	double get_distance( const point& p1 , const point& p2 ){
		return sqrt( pow( p1.x - p2.x , 2 ) + pow( p1.y - p2.y , 2 ) );
	}

	double get_cross_product( const point& a , const point& b , const point& o ){
		vector2d oa = a - o;
		vector2d ob = b - o;
		return oa.x * ob.y - ob.x * oa.y;
	}
}

using namespace geometry;
using namespace std;

typedef triangle wall;
class field;

class player{
public:
	explicit player( const field& field );
	bool is_inside( const wall& wall ) const;
	bool can_see( const player& target ) const;
	void move( const point& new_location );
	const point& get_location() const;
private:
	const field& m_field;
	point m_loc;
};

class field{
public:
	void place( const wall& w );
	wall get_wall() const;
private:
	wall m_wall;
};

player::player( const field& field ):m_field(field){}

bool player::is_inside( const wall& wall ) const{
	if(
	SAME_SIGN( get_cross_product( wall.a , wall.b , m_loc ) , get_cross_product( wall.b , wall.c , m_loc ) ) &&
	SAME_SIGN( get_cross_product( wall.b , wall.c , m_loc ) , get_cross_product( wall.c , wall.a , m_loc ) )
	){
		return true;
	}
	else{
		return false;
	}
}

bool player::can_see( const player& target ) const{
	if( this->is_inside( m_field.get_wall() ) && target.is_inside( m_field.get_wall() ) ){
		return true;
	}
	else if( this->is_inside( m_field.get_wall() ) != target.is_inside( m_field.get_wall() ) ){
		return false;
	}
	else{
		return true;
	}
}

void player::move( const point& new_location ){
	m_loc = new_location;
}

const point& player::get_location() const{
	return m_loc;
}

void field::place( const wall& wall ){
	m_wall = wall;
}

wall field::get_wall() const{
	return m_wall;
}

int main(void)
{
	int n;

	cin >> n;

	for( int i = 0 ; i < n ; i++ ){
		field f;
		player ori(f);
		player hiko(f);

		point p1, p2, p3, pk, ps;

		cin >> p1 >> p2 >> p3 >> pk >> ps;

		hiko.move(pk);
		ori.move(ps);
		wall w( p1 , p2 , p3 );
		f.place(w);

		cout << (hiko.can_see(ori) ? "NG":"OK") << endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;struct P{float x,y;int operator-=(P&a){x-=a.x;y-=a.y;}};P A,B,C,S,G;int X(P S){C.x=(B.y*S.x-B.x*S.y)/(A.x*B.y-A.y*B.x);C.y=(A.y*S.x-A.x*S.y)/(A.y*B.x-A.x*B.y);return C.x*C.y>0&&C.x+C.y<1;}main(){cin>>A.x;while(cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>S.x>>S.y>>G.x>>G.y){A-=C;B-=C;S-=C;G-=C;X(S)^X(G)?cout<<"OK\n":cout<<"NG\n";}return 0;}

C++: #include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
 
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 );
}

 double vec_abs(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}

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

int is_point_on_line(point a, point b, point c) {
  return (vec_abs(a-c) + vec_abs(c-b) < vec_abs(a-b) + EPS);
}

int inside(point p, point* ps, int n){
  segment t;
  t.a=t.b=p;
  t.b.x=DBL_MAX;

  double ymx=-DBL_MAX,ymn=DBL_MAX;
  for(int i=0;i<n;i++){
    ymx=max(ymx,ps[i].y);
    ymn=min(ymn,ps[i].y);
  }
  if(t.a.y<=ymn||t.a.y>=ymx)return 0;

  double xmx=-DBL_MAX,xmn=DBL_MAX;
  for(int i=0;i<n;i++){
    xmx=max(xmx,ps[i].x);
    xmn=min(xmn,ps[i].x);
  }
  if(t.a.x<=xmn||t.a.x>=xmx)return 0;

  int cnt=0;
  for(int i=0;i<n;i++){
    if(is_intersected_ls(ps[i],ps[i+1],t.a,t.b))cnt++;
  }
  return cnt%2;
}

int main(void){
  int n;
  point p[5],k,s;
 
  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;
 
    if(inside(k,p,3)!=inside(s,p,3))cout << "OK" << endl;
    else cout << "NG" << endl;
     
  }
 
  return 0;
}