#include <iostream>
using namespace std;

int F[102][102];


int DFS(int Y,int X,int c){
  int cnt = 0;
  if(F[Y][X] != c){
    return 0;
  }

  F[Y][X] = -1;
  cnt += DFS(Y-1,X  ,c);
  cnt += DFS(Y  ,X+1,c);
  cnt += DFS(Y+1,X  ,c);
  cnt += DFS(Y  ,X-1,c);
  return cnt;
}


int main(){
  int w,h,xs,ys,xg,yg,n;
  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0)
      break;

      for(int i=0;i<102;i++){
        for(int j=0;j<102;j++){
                F[i][j]=0;
        }
      }
    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(1){
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
  }
}
