function block(c,d,x,y){
   var dx,dy;
   if(d==0){dy=[0,0,0,0,1,1,1,1];dx=[0,1,2,3,0,1,2,3];}
   if(d==1){dy=[0,1,2,3,0,1,2,3];dx=[0,0,0,0,1,1,1,1];}
   for(var i=0;i<8;i++){
      yx[(y-1)+dy[i]][(x-1)+dx[i]]=c;
   }
}

function bomb(y,x){
   var dy=[-1,0,0,1];
   var dx=[0,-1,1,0];
   for(var i=0;i<4;i++){
      var yy=y+dy[i];
      var xx=x+dx[i];
      if(yy<0 || yy>=H || xx<0 || xx>=W)continue;
      if(yx[yy][xx]==color){yx[yy][xx]="a";bomb(yy,xx);}
   }
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var WH=(Arr.shift()).split(" ").map(Number);
   var W=WH[0];
   var H=WH[1];
   if(W==0 && H==0)break;
   var xyS=(Arr.shift()).split(" ").map(Number);
   var xS=xyS[0]-1;
   var yS=xyS[1]-1;
   var xyE=(Arr.shift()).split(" ").map(Number);
   var xE=xyE[0]-1;
   var yE=xyE[1]-1;
   var n=(Arr.shift())-0;
   var yx=[];
   for(var i=0;i<H;i++){
      yx[i]=[];
      for(var j=0;j<W;j++){
          yx[i][j]=0;
      }
   }
   for(var i=0;i<n;i++){
      var cdxy=(Arr.shift()).split(" ").map(Number);
      block.apply(null,cdxy);
   }
   var color=yx[yS][xS];
   if(color==0){console.log("NG");continue;}
   if(yx[yS][xS]==color){yx[yS][xS]="a";bomb(yS,xS);}
   var result=(yx[yE][xE]=="a")?"OK":"NG";
   console.log(result);
}