import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

bool isInside(long xp1, long yp1, long xp2, long yp2, long xp3, long yp3, long x, long y) {
    xp1 -= x;
    xp2 -= x;
    xp3 -= x;
    yp1 -= y;
    yp2 -= y;
    yp3 -= y;
    auto s1 = xp1*yp2 - xp2*yp1;
    auto s2 = xp2*yp3 - xp3*yp2;
    auto s3 = xp3*yp1 - xp1*yp3;
    return s1*s2 > 0 && s2*s3 > 0 && s3*s1 > 0;
}

void main(){
    auto n = readLong();
    foreach(i; iota(n)) {
        auto line = readLongs();
        writeln(isInside(line[0], line[1], line[2], line[3], line[4], line[5], line[6], line[7])
            ^ isInside(line[0], line[1], line[2], line[3], line[4], line[5], line[8], line[9]) ?
            "OK": "NG");
    }
}