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<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 inside(point t,point* p,int N){
  int i,count=0,j=0;
  segment lt,lp;

  p[N]=p[0];
  p[N+1]=p[1];

  lt.a=lt.b=t;
  lt.b.x=INT_MAX;

  double ymx=-DBL_MAX,ymn=DBL_MAX;
  for(i=0;i<N+1;i++){
    ymx=max(ymx,p[i].y);
    ymn=min(ymn,p[i].y);
  }
  if(lt.a.y<=ymn||lt.a.y>=ymx)return 0;
  for(i=1;i<=N;i++){
    lp.a=lp.b=p[i];

    if(!is_intersected_ls(lp.a,lp.b,lt.a,lt.b)){
      if(i==j+1){
	lp.b=p[j];
	if(is_intersected_ls(lp.a,lp.b,lt.a,lt.b))count++;
      }
      else if(ccw(lt.a,lt.b,p[i])*ccw(lt.a,lt.b,p[j])<0)count++;
      j=i;
    }
  }
  return count & 1;
}

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