#include<bits/stdc++.h>
using namespace std;

int flag=0;
int mp[102][102];
int sn[102][102];
int bc;

int px[4]={0,1,0,-1};
int py[4]={1,0,-1,0};

int slv(int xs,int ys);

int w,h,xg,yg;
int n,c,d,x,y;  

int main(){
  int xs,ys;
  while(1){
    cin>>w>>h;
    if(w==0 && h==0)return(0);
    cin>>xs>>ys;
    cin>>xg>>yg;
    flag=0;
    cin>>n;
    memset(mp,0,sizeof(mp));
    memset(sn,0,sizeof(sn));
    for(int i=0;i<n;i++){
      cin>>c>>d>>x>>y;
      if(d==1){
	for(int j=0;j<4;j++){
	  for(int k=0;k<2;k++)mp[x+k][y+j]=c;
	}
      }
      else{
	for(int j=0;j<2;j++){
	  for(int k=0;k<4;k++)mp[x+k][y+j]=c;
	}
      }
    }
    
    bc=mp[xs][ys];
    
    slv(xs,ys);
    
    if(flag)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
    
  }
}

int slv(int xs,int ys){
  if(xs==xg && ys==yg){
    flag=1;
    return(0);
  }
  
  for(int i=0;i<4;i++){
    xs+=px[i];
    ys+=py[i];
    if(bc==mp[xs][ys] && sn[xs][ys]==0){
      sn[xs][ys]=1;
      slv(xs,ys);
    }
    xs-=px[i];
    ys-=py[i];
  }
  return(0);
}