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 <complex>
#include <vector>

using namespace std;

typedef complex<double> P;

const double EPS = 1e-9;
const double PI = acos(-1);

inline double cross(const P &a, const P &b) {
    return a.real()*b.imag() - a.imag()*b.real();
}

inline int sgn(double a) {
    return a<0 ? -1 : 1;
}

void solve() {
    double x1, y1, x2, y2, x3, y3, xk, yk, xs, ys;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xk >> yk >> xs >> ys;
    P a(x1, y1), b(x2, y2), c(x3, y3);
    P k(xk, yk), s(xs, ys);
    const int ca = sgn(cross(a-k, b-k)) + sgn(cross(b-k, c-k)) + sgn(cross(c-k, a-k));
    const int cb = sgn(cross(a-s, b-s)) + sgn(cross(b-s, c-s)) + sgn(cross(c-s, a-s));
    if((abs(ca) == 3 && abs(cb) != 3) || (abs(ca) != 3 && abs(cb) == 3)) cout << "OK" << endl;
    else cout << "NG" << endl;
}

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

    int N;
    cin >> N;
    while(N--) solve();
    return 0;
}