#include <iostream>
using namespace std;

int F[105][105];
int xg,yg;
int flag = 0;

void DFS(int Y,int X,int c){
  if(F[Y][X] != c){
    return;
  }
  if(Y == xg && X == yg){
    flag = 1;
  }

  F[Y][X] = 0;
  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,n;
  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0)
      break;

    cin >> xs >> ys >> xg >> yg >> n;


    for(int i=0;i<n;i++){
      int c,d,x,y;
      cin >> c >> d >> x >> y;
      if(d == 0){
        for(int j=0;j<4;j++){
          F[x+j][y] = c;
          F[x+j][y+1] = c;
        }
      } else {
        for(int j=0;j<4;j++){
          F[x][y+j] = c;
          F[x+1][y+j] = c;
        }
      }
    }

  DFS(xs,ys,F[xs][ys]);
  if(flag == 1){
    cout << "OK" << endl;
  } else {
    cout << "NG" <<endl;
  }
  }
}

