def g;gets.split.map &:to_i;end
while(w,h=g)[0]>0
t,u=s=g;e=g
m=[v=[6]*(w+2)]+(1..h).map{[6]+[0]*w<<6}<<v
g[0].times{c,d,x,y=g;o=d<1?4:2;m[y,6-o].map{|i|i[x,o]=[c]*o}}
q=[s]
c=m[t][u]
(q.uniq!;a,b=q.shift;m[a][b]=7;[[a,b+1],[a,b-1],[a+1,b],[a-1,b]].map{|i,j|m[i][j]==c&&q<<[i,j]})while q[0]&&q[0]!=e
puts q[0]?:OK:"NG"end