require 'set'

class Graph
	def initialize
		@nodes = Set.new
		@edges = Set.new
	end

	def add_node(label = nil)
		Node.new(label)
	end

	def add_edge(u, v)
		e = Edge.new(u, v)
		u.outgoings << e
		v.incomings << e
		e
	end
	
	def del_edge(e)
		u, v = e.from, e.to
		u.outgoings.delete(e)
		v.incomings.delete(e)
		e
	end

	class Node
		def initialize(label)
			@label = label
			@outgoings = Set.new
			@incomings = Set.new
		end
		
		def to_s
			@label
		end
		attr_accessor :incomings, :outgoings, :label
	end

	class Edge
		def initialize(u, v)
			@from = u	
			@to = v
		end
		attr_reader :from, :to
	end

	def get_path_dfs(s, t, reached = Set.new)
		reached << s	
		s.outgoings.each{|e|
			v = e.to
			next if reached.include?(v)
			return [e] if v == t
			
			path = get_path_dfs(v, t, reached) 
			return [e] + path if path
		}
		nil
	end
end

def get_ints
	gets.split.map(&:to_i)
end

loop {
	w, h = get_ints
	break if w == 0
	xs, ys = get_ints
	xg, yg = get_ints
	n = gets.to_i
	
	g = Graph.new 
	nodes = (0..h+1).map{ (0..w+1).map{ g.add_node(0) } }

	n.times {
		c, d, x, y = get_ints
		for i in y..y+(d==0 ? 2 : 4)
			for j in x..x+(d==0 ? 4 : 2)
				nodes[i][j].label = c
			end
		end
	}

	for y in 1..h
		for x in 1..w
			u = nodes[y][x]
			[[1,0], [-1,0], [0,1], [0,-1]].each{|dx, dy|
				v = nodes[y+dy][x+dx]
				g.add_edge(u, v) if u.label == v.label
			}
		end
	end

	s = nodes[ys][xs]
	if s.label > 0 && g.get_path_dfs(s, nodes[yg][xg])
		puts 'OK'
	else
		puts 'NG'
	end
}