
#include <iostream>
using namespace std;

int C[102][102];
int ans;
int xg,yg;

void meiro(int W,int H,int c){
 if(W==xg && H==yg){
   ans = 1;
   return;
 }

 if(C[W][H]!=c){
   return;
 }

 C[W][H] = '.';

 meiro(W-1,H  ,c);
 meiro(W  ,H+1,c);
 meiro(W+1,H  ,c);
 meiro(W  ,H-1,c);
}

int main(){
 while(1){
   int w,h;
   cin >> w >> h;

   if(w==0 && h==0){
     break;
   }

   int xs,ys;
   cin >> xs >> ys;

   cin >> xg >> yg;

   int n;
   cin >> n;
   int c[n],d[n],x[n],y[n];

   int cbase;

   for(int i=0;i<n;i++){
     cin >> c[i] >> d[i] >> x[i] >> y[i];

     if(d[i]==0){
       for(int j=x[i];j<x[i]+4;j++){
         for(int k=y[i];k<y[i]+2;k++){
           C[j][k]=c[i];
         }
       }
     }
     if(d[i]==1){
       for(int j=x[i];j<x[i]+2;j++){
         for(int k=y[i];k<y[i]+4;k++){
           C[j][k]=c[i];
         }
       }
     }

     if(x[i]==1 &&y[i]==1){
       cbase = c[i];
     }
   }
   ans = 0;
if(cbasew == 0){
 cout << "NG"<<endl;
 continue;
}
   meiro(xs,ys,cbase);

   if(ans==1){
     cout << "OK" << endl;
   }else{
     cout << "NG" << endl;
   }
 }

 return 0;
}
