#include <iostream>
#include <vector>
#include <string>
using namespace std;



typedef vector<vector<int> > Matrix;
int w,h,xs,ys,xg,yg,n;
string res = "NG";

class Block{
public:
  int color;
  int direction;
  int x,y,dx,dy;
  void write(Matrix &board){
    if(direction == 0)
      dx = 4,dy = 2;
    else if(direction == 1)
      dx = 2,dy = 4;
    for(int i=0; i<dx; ++i){
      for(int j=0; j<dy; ++j){
	(board.at(x+i)).at(y+j) = color;
      }
    }
  }
};
  
void func(Matrix &board,int nx,int ny){
  if(board[nx][ny] == 0){
    res = "NG";
    return;
  }
  if( nx==xg && ny==yg){
    res = "OK";
    return;
  }
  int temp = board[nx][ny];
  board[nx][ny] = 0;
  if( 0<=nx-1 && temp==board[nx-1][ny])
    func(board,nx-1,ny);
  if( 0<=ny-1 && temp==board[nx][ny-1])
    func(board,nx,ny-1);
  if( nx+1<=w && temp==board[nx+1][ny])
    func(board,nx+1,ny);
  if( ny+1<=h && temp==board[nx][ny+1])
    func(board,nx,ny+1);
}


int main(void){

  while(1){
    cin >> w >> h;
    if( w==0 && h==0) return 0;
    cin >> xs >> ys >> xg >> yg >> n;
    xs--; ys--; xg--; yg--;
    Block *object[n];
    Matrix board(w, vector<int>(h,0));
    for(int i=0; i<n; ++i){
      object[i] = new Block();
      cin >> object[i]->color;
      cin >> object[i]->direction;
      cin >> object[i]->x;
      cin >> object[i]->y;
      --object[i]->x; --object[i]->y;
      object[i]->write(board);	    
    }
    func(board,xs,ys);
    cout << res << endl;
    delete[] *object;
    board.clear();
  }
  return 0;
}
  