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 <vector>
#include <cmath>
using namespace std;

int sign(int n){
	if(n < 0) return -1;
	if(n > 0) return 1;
	return 0;
}

float angle(int ax, int ay, int bx, int by, int cx, int cy){
    //angle between ab and ac
    float ab = atan2(by-ay,bx-ax);
    float ac = atan2(cy-ay,cx-ax);
    if(ab < 0)ab += 2*M_PI;
    if(ac < 0)ac += 2*M_PI;
    float ang = ac - ab;
    return (fabs(ang) < M_PI ? ang : -sign(ang) * 2 * M_PI + ang) * 180 / M_PI;
}

int isPointInTriangle(vector< int > &x, vector< int > &y, int px, int py){
	int n = x.size();
	double sum = 0;
	
	for(int i = 0; i < n; ++i){
		sum += angle(px, py, x[i], y[i], x[(i+1)%n], y[(i+1)%n]);
	}
	
	return (sum > 350 ? 1 : -1) ;
}

int main(){
	int n;
	int xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
	vector< int > x(3, 0);
	vector< int > y(3, 0);
	
	cin >> n;
	
	for(int i = 0; i < n; ++i){
		cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
		
		x[0] = xp1;
		x[1] = xp2;
		x[2] = xp3;
		
		y[0] = yp1;
		y[1] = yp2;
		y[2] = yp3;
		
		cout << (isPointInTriangle(x, y, xk, yk) * isPointInTriangle(x, y, xs, ys) < 0 ? "OK" : "NG") << endl;
	}
	return 0;
}