#include<iostream>
using namespace std;

char F[102][102];

void DFS(int x,int y,char c){
  if(F[x][y]!=c)
    return;
  F[x][y]='@';
  DFS(x-1,y,c);
  DFS(x,y+1,c);
  DFS(x+1,y,c);
  DFS(x,y-1,c);
}
void Block(int c,int d,int x,int y){
  char b;
  if(c=0)
    b='+';
  if(c=1)
    b='-';
  if(c=2)
    b='*';
  if(c=3)
    b='/';
  F[x][y]=b;
  F[x][y+1]=b;
  F[x+1][y]=b;
  F[x+1][y+1]=b;
  if(d==1){
    F[x][y+2]=b;
    F[x][y+3]=b;
    F[x+1][y+2]=b;
    F[x+1][y+3]=b;
  }else{
    F[x+2][y]=b;
    F[x+2][y+1]=b;
    F[x+3][y]=b;
    F[x+3][y+1]=b;
  }
}

int main(){
  int w=1,h;
  int xs,ys;
  int xg,yg;
  int n;
  int c,d,x,y;
  while(w>0){
    cin>>w>>h;
    if(w==0&&h==0)
      break;
    for(int i=0;i<w;i++){
      for(int j=0;j<h;j++){
        F[i][j]='.';
      }
    }
    cin>>xs>>ys;
    cin>>xg>>yg;
    cin>>n;
    for(int i=0;i<n;i++){
      cin>>c>>d>>x>>y;
      Block(c,d,x,y);
    }
    DFS(xs,yscout<<endl;,F[xs][ys]);
    if(F[xg][yg]=='@')
      cout<<"OK"<<endl;
    else
      cout<<"NG"<<endl;
  }
}

