#include<iostream>
using namespace std;

char F[102][102];
void DFC(int y,int x);
void block_set(int c,int d,int x,int y);
int cs;
int xg,yg;
bool result = false;

int main(){
  int H,W;
  while(1){
    result = false;
    cin >> H >> W;
    if(H==0&&W==0)
      break;
    int xs,ys;
    cin >> xs >> ys >> xg >> yg;
    int n;
    cin >> n;
    int c,d,x,y;
    for(int i=0;i<n;i++){
      cin >> c >> d >> x >> y;
      if(i==0)
        cs = c;
        block_set(c,d,x,y);
    }

    DFC(xs,ys);

    if(result)
      cout << "OK" << endl;
      else
      cout << "NG" << endl;
  }

  return 0;
}

void DFC(int x,int y){
  if(F[x][y]!=cs)
    return;

  if(x==xg,y==yg)
    result = true;

  F[x][y]=0;

  DFC(x-1,y);
  DFC(x+1,y);
  DFC(x,y-1);
  DFC(x,y+1);
}

void block_set(int c,int d,int x,int y){
  for(int i=0;i<2;i++){
    for(int j=0;j<4;j++){
      if(d){
        F[x+i][y+j] = c;
      }
      else{
        F[x+j][y+i] = c;
      }
    }
  }
}

