#include<iostream>
using namespace std;

int a=0;
int F[102][102];
void DFS(int Xs,int Ys,int c,int Xg,int Yg){
  if(F[Xs][Ys]!=c){
    return;
  }else if(Xs==Xg&&Ys==Yg){
    a=1;
    return;
  }
 F[Xs][Ys]=0;
 DFS(Xs-1,Ys,c,Xg,Yg);
 DFS(Xs,Ys-1,c,Xg,Yg);
 DFS(Xs+1,Ys,c,Xg,Yg);
 DFS(Xs,Ys+1,c,Xg,Yg);
}

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

