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



typedef vector<vector<int> > Matrix;
int w,h,xs,ys,xg,yg,n,flag;

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-1)).at(y+j-1) = color;
      }
    }
  }
};
  
void func(Matrix &board,int nx,int ny){
  if( nx==xg && ny==yg) flag = 1;
  else if( w<=nx+1 || h<=ny+1) return;
  if(board[nx-1][ny-1]==board[nx][ny-1])
    func(board,nx+1,ny);
  if(board[nx-1][ny-1]==board[nx-1][ny])
    func(board,nx,ny+1);
}


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