
def oprd(t0, t1, p)
  x0 = t1[0] - t0[0]
  y0 = t1[1] - t0[1]
  x1 = p[0] - t0[0]
  y1 = p[1] - t0[1]
  x0 * y1 - x1 * y0
end

def inside?(tps, pt)
  d0 = oprd(tps[0, 2], tps[2, 2], pt)
  d1 = oprd(tps[2, 2], tps[4, 2], pt)
  d2 = oprd(tps[4, 2], tps[0, 2], pt)

  (d0 > 0 && d1 > 0 && d2 > 0) ||(d0 < 0 && d1 < 0 && d2 < 0)
end

### main

n = gets.strip.to_i

n.times.each do
  tps = gets.strip.split(' ').map{|s| s.to_i}

  ap = tps[6, 2]
  bp = tps[8, 2]
  tps = tps[0, 6]

  a_in = inside?(tps, ap)
  b_in = inside?(tps, bp)

  puts (a_in && ! b_in || ! a_in && b_in) ? "OK" : "NG"
end