//23
#include<iostream>

using namespace std;

int w,h;

void ff(int (*g)[101],int c,int y,int x){
  if(1<=y&&y<=h&&1<=x&&x<=w&&g[y][x]==c){
    g[y][x]=-1;
    int d[]={0,1,0,-1,0};
    for(int i=0;i<4;i++){
      ff(g,c,y+d[i],x+d[i+1]);
    }
  }
}

int main(){
  for(;cin>>w>>h,w|h;){
    int g[101][101]={{}};
    int sx,sy,gx,gy;
    cin>>sx>>sy>>gx>>gy;
    int n;
    cin>>n;
    while(n--){
      int c,d,x,y;
      cin>>c>>d>>x>>y;
      for(int i=0;i<2+2*d;i++){
	for(int j=0;j<4-2*d;j++){
	  g[i+y][j+x]=c;
	}
      }
    }
    ff(g,g[sy][sx],sy,sx);
    cout<<((g[gy][gx]==-1)?"OK":"NG")<<endl;
  }
  return 0;
}