#include<iostream>
#include<queue>
#include<map>
using namespace std;

const int size = 110;
int board[size][size];
int visited[size][size];
int xblocks[2][8] = { {0, 1, 2, 3, 0, 1, 2, 3},
		      {0, 0, 0, 0, 1, 1, 1, 1} };
int yblocks[2][8] = { {0, 0, 0, 0, 1, 1, 1, 1},
		      {0, 1, 2, 3, 0, 1, 2, 3} };
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main() {
  int w,h,xs,ys,xg,yg,n,c,d,x,y;
  while(cin>>w>>h, w|h) {
    for(int i=0; i<size; ++i)
      for(int j=0; j<size; ++j) {
	board[i][j] = 0;
	visited[i][j] = 0;
      }

    cin>>xs>>ys;
    cin>>xg>>yg;
    cin>>n;
    for(int i=0; i<n; ++i) {
      cin>>c>>d>>x>>y;
      for(int j=0; j<8; ++j)
	board[x+xblocks[d][j]][y+yblocks[d][j]] = c;
    }

    queue<pair<int,int> > Q;
    Q.push(pair<int,int>(xs,ys));
    while(!Q.empty()) {
      pair<int,int> pos = Q.front(); Q.pop();
      int nx = pos.first,ny = pos.second;
      if(visited[ny][nx]) continue;
      visited[ny][nx] = 1;
      if(nx == xg && ny == yg) {
	cout<<"OK"<<endl;
	goto NEXT;
      }

      for(int i=0; i<4; ++i) {
	if(nx+dx[i] > 0 && nx+dx[i] <= w &&
	   ny+dy[i] > 0 && ny+dy[i] <= h &&
	   board[ny][nx] == board[ny+dy[i]][nx+dx[i]])
	  Q.push(pair<int,int>(nx+dx[i],ny+dy[i]));
      }
      board[ny][nx] = -1;
    }
    cout<<"NG"<<endl;
  NEXT:
    ;
  }
}