import java.lang.Math.sqrt

fun main(args:Array<String>):Unit {
    repeat(readLine()!!.trim().toInt()){
        val arg = readLine()!!.trim().split(' ').map(String::toInt)
        val points = Array(5){
            val (x, y) = arg.drop(it * 2).take(2)
            Point(x, y)
        }
        val (a, b, c, d, e) = points
        val edge = Edge(d, e)
        val ta = Edge(a, b)
        val tb = Edge(b, c)
        val tc = Edge(c, a)
        println(if (listOf(ta, tb, tc).count{edge.isCross(it)} == 1) "OK" else "NG")
    }
}
data class Vector(val x:Int, val y:Int){
    fun cross(that:Vector):Int = x * that.y - y * that.x
    fun sin(that:Vector):Double = cross(that) / length / that.length
    val length:Double
        get() = sqrt(x.toDouble() * x + y * y)
    constructor(from:Point, to:Point):this(to.x - from.x, to.y - from.y)
}
data class Point(val x:Int, val y:Int)
data class Edge(val from:Point, val to:Point){
    fun isCross(that:Edge):Boolean {
        val eVec = Vector(from, to)
        val ffVec = Vector(from, that.from)
        val ftVec = Vector(from, that.to)
        val tVec = Vector(that.from, that.to)
        val tffVec = Vector(that.from, from)
        val tftVec = Vector(that.from, to)
        return eVec.sin(ffVec) * eVec.sin(ftVec) <= 0 && tVec.sin(tffVec) * tVec.sin(tftVec) <= 0
    }
}
