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++: # define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;

# define INF ((int)(1<<30))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12


class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0) :x(x), y(y) {}


	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double k) { return Point(x * k, y * k); }
	Point operator / (double k) { return Point(x / k, y / k); }
	bool operator < (const Point &p)const { return x != p.x ? x < p.x : y < p.y; }
	bool operator ==(const Point &p)const { return fabs(x - p.x) < EPS&&fabs(y - p.y) < EPS; }

	double abs() { return sqrt(norm()); }
	double norm() { return x*x + y*y; }
};
typedef Point Vector;
struct Segment
{
	Point p1, p2;
};
typedef Segment Line;
class Circle
{
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0) :c(c), r(r) {}
};

double dot(Vector a, Vector b) { return a.x*b.x + a.y*b.y; }//??????
double cross(Vector a, Vector b) { return a.x*b.y - a.y*b.x; }//??????
bool isOrthogonal(Vector a, Vector b) { return fabs(dot(a, b)) < EPS; }//??´??????
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) { return isOrthogonal(a1 - a2, b1 - b2); }
bool isOrthogonal(Line l1, Line l2) { return fabs(dot(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
bool isParallel(Vector a, Vector b) { return fabs(cross(a, b)) < EPS; }//?????????
bool isParallel(Point a1, Point a2, Point b1, Point b2) { return isParallel(a1 - a2, b1 - b2); }
bool isParallel(Line l1, Line l2) { return fabs(cross(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
Point project(Line s, Point p)
{
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base*r;
}


template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

bool hoge(Vector a, Vector b, Vector c, Vector p)
{
	double cr1 = cross(b-a, p-b);
	double cr2 = cross(c-b, p-c);
	double cr3 = cross(a-c, p-a);
	if ((cr1 > 0 && cr2 > 0 && cr3 > 0) || (cr1 < 0 && cr2 < 0 && cr3 < 0))return false;
	return true;
}

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		Vector p[3], k, s;
		for (int i = 0; i < 3; i++)
		{
			cin >> p[i].x >> p[i].y;
		}
		cin >> k.x >> k.y;
		cin >> s.x >> s.y;
		if (hoge(p[0], p[1], p[2], k) != hoge(p[0], p[1], p[2], s))cout << "OK" << endl;
		else cout << "NG" << endl;
	}
}

C++: /*
Hokudai Practice Contest 2014
H - Altair and Vega

ティツァツ」テヲツウツ陛ッツシツ堙ァツつケテ」ツ?ョテ・ツ??・ツ個?・ツ按、テ・ツョツ?
ティツィツ暗ァツョツ療・ツケツセテ、ツスツ陛」ツ?ョテ・ツ閉湘ゥツ。ツ古」ツ??
テァツつケテ」ツ?古、ツクツ嘉ィツァツ津・ツスツ「テ」ツ?ォテ・ツ??・ツ個?」ツ?陛」ツつ古」ツ?ヲテ」ツ??」ツつ凝」ツ?凝」ツつ津・ツ按、テ・ツョツ堙」ツ?ァテ」ツ?催」ツつ古」ツ?ーテ」ツつ暗」ツ??」ツ??
テ・ツ??・ツ個?・ツ按、テ・ツョツ堙」ツ?ォテ」ツ?ッテ」ツ??」ツつ催」ツ??」ツつ催」ツ?ェテヲツ鳴ケテヲツウツ陛」ツ?古」ツ?づ」ツつ凝」ツ?古」ツ??
 |テ「ツ鳴ウabc| = |テ「ツ鳴ウabx| + |テ「ツ鳴ウbcx| + |テ「ツ鳴ウcax|
テ」ツ?古ヲツ按静」ツつ甘ァツォツ凝」ツ?」テ」ツ?ヲテ」ツ??」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ?凝」ツつ津」ツδ?」ツつァテ」ツδε」ツつッテ」ツ?凖」ツつ凝ヲツ鳴ケテヲツウツ陛」ツ?古ァツーツ。テ・ツ債佚」ツ?ァテ」ツ?づ」ツつ凝」ツ??

テァツ可ステァツ可崚」ツ?ィテァツケツ氾・ツ・ツウテ」ツ?古」ツ?ィテ」ツつづ」ツ?ォテ・ツ青古」ツ?佚、ツクツ嘉ィツァツ津・ツスツ「テ」ツ?ォテ・ツ青ォテ」ツ?セテ」ツつ古」ツつ凝」ツつアテ」ツδシテ」ツつケテ」ツ?ォテヲツウツィテヲツ?湘」ツ?凖」ツつ凝」ツ??

テ・ツケツセテ、ツスツ陛・ツ閉湘ゥツ。ツ古」ツ?ィテ」ツ?療」ツ?ヲテ」ツ?ッテ」ツ?凝」ツ?ェテ」ツつ甘・ツ按敕ァツュツ嘉」ツ?ョテ・ツ閉湘ゥツ。ツ古」ツ?ァテ」ツ?！CPCテ」ツ?ァテ・ツョツ淌ゥツ堋崚」ツ?ォテ・ツ?コテゥツ。ツ古」ツ?陛」ツつ古」ツつ凝・ツケツセテ、ツスツ陛」ツ?ッテヲツ閉ーテヲツョツオテゥツ崢」テ」ツ?療」ツ??」ツ??

テヲツ卍づゥツ鳴禿ィツィツ暗ァツョツ療ゥツ?湘ッツシツ唹(1)
*/

#include<iostream>
#include<complex>
using namespace std;

//テ・ツケツセテ、ツスツ陛・ツ閉湘ゥツ。ツ古」ツ?ァテ」ツ?ッテゥツ?づァツつケテ」ツつ津ィツ。ツィテ」ツ?凖」ツ?ョテ」ツ?ォcomplexテ・ツ楪?ティツ、ツ?ァツエツ?ヲツ閉ーテ・ツ楪?テ」ツつ津ァツ板ィテ」ツ??」ツつ凝」ツ?禿」ツ?ィテ」ツ?古」ツ?ァテ」ツ?催」ツつ?
//ティツ、ツ?ァツエツ?ヲツ閉ーテ」ツつ津」ツ??ィツ、ツ?ァツエツ?・ツケツウテゥツ敖「テ、ツクツ甘」ツ?ョテ」ツδ凖」ツつッテ」ツδ暗」ツδォテ」ツ?ィティツヲツ凝」ツ?ェテ」ツ?療」ツ?ヲテ・ツ?ヲテァツ青?」ツ?凖」ツつ?
//テ、ツセツソテ・ツ按ゥテ」ツ?ェテゥツ鳴「テヲツ閉ーテ」ツ?ィテ」ツ?療」ツ?ヲテ」ツ??・ツ環?ヲツクツ崚ァツョツ療」ツつ?」ツつケテ」ツつォテ」ツδゥテ」ツδシテ・ツ?催」ツ??ァツオツカテ・ツッツセテ・ツ?、ティツィツ暗ァツョツ療」ツ?ェテ」ツ?ゥテ」ツ?古・ツ按ゥテァツ板ィテ」ツ?ァテ」ツ?催」ツつ?
typedef complex<double> P;
const double EPS = 1e-9;

//テ・ツ、ツ姪ァツゥツ?
double cross(P x,P y){return real(x)*imag(y) - imag(x)*real(y);}

//テ、ツクツ嘉ィツァツ津・ツスツ「テ」ツ?ョテゥツ敖「テァツゥツ?
double area(P a,P b,P c){ return abs(cross(b-a,c-a)/2); }

//テ、ツクツ嘉ィツァツ津・ツスツ「abcテ」ツ?ォテァツつケxテ」ツ?古・ツ青ォテ」ツ?セテ」ツつ古」ツ?ヲテ」ツ??」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ?凝」ツつ津・ツ按、テ・ツョツ?
bool inter(P a,P b,P c,P x){
  //テヲツオツョテ・ツ仰陛・ツーツ湘ヲツ閉ーテァツつケテヲツシツ氾ァツョツ療」ツ?ァテ」ツ?ッティツェツ、テ・ツキツョテ・ツ?ヲテァツ青?」ツつ津ィツ。ツ古」ツ??
  //テ」ツ?警 > y +EPSテ」ツ?催」ツ?ッテゥツ?堙・ツクツクテ」ツ?ョティツィツ暗ァツョツ療」ツ?ォテ」ツ?甘」ツ?妥」ツつ凝」ツ?警>yテ」ツ?催」ツ?ォテ・ツスツ禿」ツ?淌」ツつ?
  //テ」ツ?警 > y -EPSテ」ツ?催」ツ?づ」ツつ凝」ツ??」ツ?ッテ」ツ?警 +EPS > yテ」ツ?催」ツ?ッテゥツ?堙・ツクツクテ」ツ?ョティツィツ暗ァツョツ療」ツ?ォテ」ツ?甘」ツ?妥」ツつ凝」ツ?警>=yテ」ツ?催」ツ?ォテ・ツスツ禿」ツ?淌」ツつ?
  if( area(a,b,x) + area(b,c,x) + area(c,a,x) > area(a,b,c) + EPS)return false;
  return true;
}

int main(){
  int n;
  P p1,p2,p3,pk,ps;

  cin >> n;

  for(int i=0;i<n;i++){
    double x,y;
    cin >> x >> y; p1 = P(x,y);
    cin >> x >> y; p2 = P(x,y);
    cin >> x >> y; p3 = P(x,y);
    cin >> x >> y; pk = P(x,y);
    cin >> x >> y; ps = P(x,y);

    //テ、ツクツ嘉ィツァツ津・ツスツ「テ」ツ?ォテ・ツ青古ヲツ卍づ」ツ?ォテ・ツ青ォテ」ツ?セテ」ツつ古」ツ?ヲテ」ツ??」ツ?ェテ」ツ??」ツ?凝・ツ按、テ・ツョツ?
    if(inter(p1,p2,p3,pk) != inter(p1,p2,p3,ps) )cout << "OK" << endl;
    else cout << "NG" << endl;
  }
  
}