### constant

BLOCK = [[4, 2], [2, 4]]
NBRS = [[1, 0], [0, 1], [-1, 0], [0, -1]]

### main

while true
  w, h = gets.strip.split(' ').map{|s| s.to_i}
  break if w == 0 && h == 0

  bds = h.times.map{[0] * w}
  visited = h.times.map{[false] * w}

  xs, ys = gets.strip.split(' ').map{|s| s.to_i}
  xs -= 1
  ys -= 1

  xg, yg = gets.strip.split(' ').map{|s| s.to_i}
  xg -= 1
  yg -= 1

  n = gets.strip.to_i

  n.times.each do
    c, d, x, y = gets.strip.split(' ').map{|s| s.to_i}
    x -= 1
    y -= 1

    for dy in (0...BLOCK[d][1])
      for dx in (0...BLOCK[d][0])
        bds[y + dy][x + dx] = c
      end
    end
  end

  cs = bds[ys][xs]
  visited[ys][xs] = true
  q = [[xs, ys]]

  reached = false

  while ! q.empty?
    x, y = q.shift
    if x == xg && y == yg
      reached = true
      break
    end

    for nb in NBRS
      xn = x + nb[0]
      yn = y + nb[1]

      if xn >= 0 && xn < w && yn >= 0 && yn < h &&
          ! visited[yn][xn] && bds[yn][xn] == cs
        q << [xn, yn]
        visited[yn][xn] = true
      end
    end
  end

  puts (reached ? "OK" : "NG")
end