#include <iostream>

#define rep(i, a, b) for(int i = a; i < b; i ++)

using namespace std;

int w, h, xs, ys, xg, yg, n;
int map[100][100] = {0};
int map2[100][100] = {0};
void exp(int x, int y, int c) {
  if(x <= 0 || w <= x || y <= 0 || h <= y) return;
  if(map[x][y] != c || map2[x][y] == 1) return;

  map2[x][y] = 1;

  exp(x-1, y, c);
  exp(x+1, y, c);
  exp(x, y-1, c);
  exp(x, y+1, c);

  return;
}

int main() {
  while(cin >> w >> h >> xs >> ys >> xg >> yg >> n, w) {
    rep(i, 0, h) {
      rep(j, 0, w) {
	map[j][i] = 0;
	map2[j][i] = 0;
      }
    }

    int block[4];
    int start[4];
    rep(i, 0, n) {
      rep(lp, 0, 4) {
	cin >> block[lp];
      }

      switch(block[1]) {
      case(0):
	rep(y, 0, 2) {
	  rep(x, 0, 4) {
	    map[block[2]+x][block[3]+y] = block[0];
	  }
	}
	break;
      case(1):
	rep(y, 0, 4) {
	  rep(x, 0, 2) {
	    map[block[2]+x][block[3]+y] = block[0];
	  }
	}
	break;
      }
    }
    if(map[xs][ys] == 0 || map[xg][yg] == 0 || map[xs][ys] != map[xg][yg]) {
      cout << "NG" << endl;
    }
    else {
      exp(xs, ys, map[xs][ys]);
      cout << ((map2[xg][yg] == 1)?("OK"):("NG")) << endl;
    }
  }    
  return 0;
}