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<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
typedef long long ll;
typedef unsigned long long ull;
double ab,ac,bc;
double ak,bk,ck,as,bs,cs;
bool heron(){
    double sta;
    double wa = 0.0;
    double S,s;
    bool f1=false,f2=false; 
    /*sta*/
    s = (ab+ac+bc)*0.5;
    S = sqrt(s * (s-ab) * (s-ac) * (s-bc));
    sta = S;

    /*wa*/
    s = (ab+ak+bk)*0.5;
    S = sqrt(s*(s-ab)*(s-ak)*(s-bk));
    wa += S;
    s = (ac+ak+ck)*0.5;
    S = sqrt(s*(s-ac)*(s-ak)*(s-ck));
    wa += S;
    s = (bc+bk+ck)*0.5;
    S = sqrt(s*(s-bc)*(s-bk)*(s-ck));
    wa += S;
    if(fabs(sta-wa) <= 0.01)f1 = true;
    wa = 0.0;

    s = (ab+as+bs)*0.5;
    S = sqrt(s*(s-ab)*(s-as)*(s-bs));
    wa += S;
    s = (ac+as+cs)*0.5;
    S = sqrt(s*(s-ac)*(s-as)*(s-cs));
    wa += S;
    s = (bc+bs+cs)*0.5;
    S = sqrt(s*(s-bc)*(s-bs)*(s-cs));
    wa += S;
    if(fabs(sta-wa) <= 0.01)f2 = true;

    if((f1 && f2) || (!f1 && !f2))return false;
    else return true;
}
int main(){
    int hoge;
    scanf("%d",&hoge);
    while( hoge-- ){
        double xa,ya,xb,yb,xc,yc,xk,yk,xs,ys;
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xk,&yk,&xs,&ys);
        ab = sqrt((xa-xb)*(xa-xb) + (ya-yb)*(ya-yb));
        ac = sqrt((xa-xc)*(xa-xc) + (ya-yc)*(ya-yc));
        bc = sqrt((xb-xc)*(xb-xc) + (yb-yc)*(yb-yc));
        ak = sqrt((xa-xk)*(xa-xk) + (ya-yk)*(ya-yk));
        bk = sqrt((xb-xk)*(xb-xk) + (yb-yk)*(yb-yk));
        ck = sqrt((xc-xk)*(xc-xk) + (yc-yk)*(yc-yk));
        as = sqrt((xa-xs)*(xa-xs) + (ya-ys)*(ya-ys));
        bs = sqrt((xb-xs)*(xb-xs) + (yb-ys)*(yb-ys));
        cs = sqrt((xc-xs)*(xc-xs) + (yc-ys)*(yc-ys));
        bool f = heron();
        (f) ? puts("OK") : puts("NG");
    }
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

#include <complex>
typedef complex<double> Point;
const double EPS = 1e-8;

// テ・ツ?・テ・ツ環崚」ツつケテ」ツδ暗」ツδェテ」ツδシテ」ツδ?」ツ?凝」ツつ嘉・ツョツ淌ヲツ閉ーテ、ツコツ古」ツ?、テ」ツつ津」ツ?ィテ」ツ?」テ」ツ?ヲ Point テ」ツ?ク
istream& operator >> ( istream &s, Point &a )
{
	double r, i;
	s >> r >> i;
	a = Point( r, i );
	return s;
}

// テ・ツ、ツ姪ァツゥツ催ッツシツ暗」ツつッテ」ツδュテ」ツつケテァツゥツ催ッツシツ?
double cross( const Point &a, const Point &b )
{
	return a.real() * b.imag() - a.imag() * b.real();
}

// CCW テゥツ鳴「テヲツ閉ーテ」ツ?? -> b -> c テ」ツ?ィテゥツ?イテ」ツつ?」ツ?ィテ」ツ?催」ツ??・ツ渉催ヲツ卍づィツィツ暗・ツ崢榲」ツつ甘」ツ?ェテ」ツつ?1, テァツ崢エテゥツ?イテ」ツ?ェテ」ツつ?0, テヲツ卍づィツィツ暗・ツ崢榲」ツつ甘」ツ?ェテ」ツつ?-1
// include : cross
int ccw( const Point &a, const Point &b, const Point &c )
{
	if ( cross( ( b - a ), ( c - a ) ) < -EPS )
	{
		return -1;
	}
	else if ( EPS < cross( ( b - a ), ( c - a ) ) )
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

// テァツつケ p テ」ツ?古・ツ、ツ堙ィツァツ津・ツスツ「 qs テ」ツ?ョテ・ツ??ゥツδィテ」ツ?ォテ」ツ?づ」ツつ凝」ツ??( Winding Number Algorithm) :TODO
// include : ccw
bool point_in_polygon( const Point &p, const vector<Point> &qs )
{
	const int N = qs.size();
	
	int wn = 0;
	for ( int i = 0; i < N; ++i )
	{
		const Point &s = qs[i], &t = qs[ ( i + 1 ) % N ];
		if ( s.imag() - EPS <= t.imag() && s.imag() - EPS < p.imag() && p.imag() + EPS < t.imag() ) // テ、ツクツ甘・ツ青妥」ツ?催」ツ?ョティツセツコ
		{
			wn += ccw( s, p, t ) == -1;
		}
		else if ( t.imag() - EPS <= s.imag() && t.imag() - EPS < p.imag() && p.imag() + EPS < s.imag() )
		{
			wn -= ccw( t, p, s ) == -1;
		}
	}
	return wn;
};

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	int n;
	cin >> n;
	REP( i, 0, n )
	{
		vector<Point> tri( 3 );
		REP( j, 0, 3 )
		{
			cin >> tri[j];
		}
		Point s, t;
		cin >> s >> t;

		cout << ( point_in_polygon( s, tri ) ^ point_in_polygon( t, tri ) ? "OK" : "NG" ) << endl;
	}

	return 0;
}