#include<iostream>
using namespace std;

int F[102][102];

void DFS(int Y,int X,int C){
   if(F[Y][X]!=C)
      return;
   F[Y][X]=6;
   DFS(Y-1,X,C);
   DFS(Y,X+1,C);
   DFS(Y+1,X,C);
   DFS(Y,X-1,C);
} 

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