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>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;

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 P {
	double x,y;
	P(){}
	P(double x,double y) : x(x), y(y){
	}
	P operator + (P p){
		return P(add(x, p.x), add(y, p.y));
	}
	P operator - (P p){
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator * (double d){
		return P(x * d, y * d);
	}
	double dot(P p){	// ??????
		return add(x * p.x, y * p.y);
	}
	double det(P p){	// ??????
		return add(x * p.y, -y * p.x);
	}
};

int main(){
	int n;
	vector<P> p(5);
	cin>>n;
	while(n--){
		rep(i, 5) cin>>p[i].x>>p[i].y;
		bool f1 =true, f2 = true;
		for(int i = 0; i < 3; i++){
			if((p[3]-p[i]).det(p[(i+1)%3]-p[i])>0
				!=(p[3]-p[(i+1)%3]).det(p[(i+2)%3]-p[(i+1)%3])>0){
				f1 = false;
				break;
			}
		}
		for(int i = 0; i < 3; i++){
			if(((p[4]-p[i]).det(p[(i+1)%3]-p[i])>0)
				!=((p[4]-p[(i+1)%3]).det(p[(i+2)%3]-p[(i+1)%3])>0)){
				f2 = false;
				break;
			}
		}
		cout<<(f1^f2?"OK":"NG")<<endl;
	}
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
struct Point { long double px, py; };
Point Minus(Point a, Point b) { Point O; O.px = a.px - b.px; O.py = a.py - b.py; return O; }
long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; }
long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; }
int contain(vector<Point> v, Point p) {
	bool in = false;
	for (int i = 0; i < v.size(); ++i) {
		Point a = Minus(v[i], p), b = Minus(v[(i + 1) % v.size()], p);
		if (a.py > b.py) swap(a, b);
		if (a.py <= 0 && 0 < b.py)
			if (crs(a, b) < 0) in = !in;
		if (crs(a, b) == 0 && dot(a, b) <= 0) return 1;
	}
	return in ? 2 : 0;
}
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		Point p1, p2, p3, p4, p5;
		cin >> p1.px >> p1.py >> p2.px >> p2.py >> p3.px >> p3.py >> p4.px >> p4.py >> p5.px >> p5.py;
		vector<Point>C = { p1,p2,p3 };
		bool G1 = contain(C, p4), G2 = contain(C, p5);
		if (G1 ^ G2 == true)cout << "OK" << endl;
		else { cout << "NG" << endl; }
	}
	return 0;
}

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

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))
typedef complex<double> Po;

Po unit(Po p){return p / abs(p);}
  
Po normal(Po p,int m){
  Po x;
  if(!m)x = p * Po(0,1);
  else x = p * Po(0,-1);
  return x;
}

double dot(Po x,Po y){return x.real()*y.real() + x.imag()*y.imag();}

double cross(Po x,Po y){return x.real()*y.imag() - x.imag()*y.real();}

double area(Po a,Po b,Po c){
  return abs(cross(b-a,c-a)/2);
}

bool inter(Po a,Po b,Po c,Po x){
  if( area(a,b,x) + area(b,c,x) + area(c,a,x) > area(a,b,c) +EPS)return false;
  else return true;
}

double heron(double a,double b,double c){
  double s = (a+b+c)/2;
  return sqrt(s*(s-a)*(s-b)*(s-c));
}

class line{
 public:
  Po a,b;

  void set(Po x,Po y){
    a = x;
    b = y;
  }

  bool orth(line l){
    return EQ( dot(a-b,l.a-l.b),0.0);
  }

  bool para(line l){
    return EQ( cross(a-b,l.a-l.b),0.0);
  }

  bool on_line(Po x){
    return EQ( cross(b-a,x-a),0.0);
  }

  double line_dis(Po x){
    return abs(cross(b-a,x-a))/abs(b-a);
  }

  Po line_cp(line l){
    return a + (b-a)*cross(l.b-l.a,l.a-a) /cross(l.b-l.a,b-a);
  }

  bool on_seg(Po x){
    return (abs(a-x) + abs(x-b) < abs(a-b) + EPS);
  }

  double seg_dis(Po x){
    if(dot(b-a,x-a)<EPS)return abs(x-a);
    if(dot(a-b,x-b)<EPS)return abs(x-b);
    return abs(cross(b-a,x-a))/abs(b-a);
  }

  int is_cross(line l){
    return (cross(b-a,l.a-a) * cross(b-a,l.b-a)<EPS) && (cross(l.b-l.a,a-l.a) * cross(l.b-l.a,b-l.a) < EPS);
  }

  Po seg_cp(line l){
    double d = abs(cross(l.b-l.a,a-l.a));
    return a + (b-a)*( d / (d * abs(cross(l.b-l.a,b-l.a))));
  }
};

class polygon{
 public:
  vector<Po> v;
  int o;

  void set(void){
    v.clear();
  }

  void Vadd(Po a){
    if(!v.size())o = 0;
    else if(a.imag() < v[o].imag())o = v.size();
    v.push_back(a);
  }

  void sort(void){
    vector<double> seta;
    Po ot;
    ot.real() = 1.0;
    ot.imag() = 0.0;
    swap(v[0],v[o]);
    o = 0;
    for(int i=1;i<(int)v.size();i++){
      seta.push_back(dot(ot,v[i]-v[0]) / (abs(ot)*abs(v[i]-v[0])) );
    } 
    for(int i=1;i<(int)v.size()-1;i++){
      for(int j=i+1;j<(int)v.size();j++){
	if(seta[i-1] < seta[j-1]){
	  swap(seta[i-1],seta[j-1]);
	  swap(v[i],v[j]);
	}
      }
    }
  }

  bool inter(Po a){
    int c = 0;
    double max = 0;
    Po b;
    line l,s;
    vector<int> tmp;
    for(int i=0;i<(int)v.size();i++){
      if(max < v[i].real())max = v[i].real();
      if(a.imag() == v[i].imag()){
	tmp.push_back(1);
	v[i].imag() += 1e-6;
      }else tmp.push_back(0);
    }
    b.real() = max+1;
    b.imag() = a.imag();
    s.set(a,b);
    for(int i=0;i<(int)v.size()-1;i++){
      l.set(v[i],v[i+1]);
      if(s.is_cross(l))c++;
    }
    l.set(v[(int)v.size()-1],v[0]);
    if(s.is_cross(l))c++;
    for(int i=0;i<(int)v.size();i++){
      if(tmp[i])v[i].imag() -= 1e-6;
    }
    if(c%2)return true;
    else return false;
  }
};

int main(){
  int n;
  Po p1,p2,p3,pk,ps;
  polygon tri;

  cin >> n;

  for(int i=0;i<n;i++){
    cin >> p1.real() >> p1.imag();
    cin >> p2.real() >> p2.imag();
    cin >> p3.real() >> p3.imag();
    cin >> pk.real() >> pk.imag();
    cin >> ps.real() >> ps.imag();
    
    tri.set();
    tri.Vadd(p1);
    tri.Vadd(p2);
    tri.Vadd(p3);
    tri.sort();
    
    if(tri.inter(pk) != tri.inter(ps))cout << "OK" << endl;
    //if(inter(p1,p2,p3,pk) != inter(p1,p2,p3,ps) )cout << "OK" << endl;
    else cout << "NG" << endl;
  }
  
}