#include <bits/stdc++.h>

#define rep(i, j) FOR(i, 0, j)
#define rep2(i, k) for(int i = 1; i <= k; ++i)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define INF (1 << 30)

using namespace std;
 
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int field[105][105];
int h, w, sx, sy, gx, gy, n;
int col, dire, x, y;
int scol;

bool dfs(int nx, int ny) {
	field[ny][nx] = 0;
	if(nx == gx && ny == gy) return true;
	rep(i, 4) {
		int tx = nx + dx[i];
		int ty = ny + dy[i];
		if(tx <= w && tx > 0 && ty <= h && field[ty][tx] == scol) dfs(tx, ty);
	}
	return false;
}

int main() {
	while(cin >> w >> h, w || h) {
		memset(field, 0, sizeof(field));
		int scol = 0;
		cin >> sx >> sy >> gx >> gy;
		cin >> n;
		rep(k, n) {
			cin >> col >> dire >> x >> y;
			if(dire) {
				rep(i, 4) rep(j, 2) field[y + i][x + j] = col;
			}
			else {
				rep(i, 2) rep(j, 4) field[y + i][x + j] = col;
			}
			//rep(j, (dire?4:2)) rep(k, (dire?2:4)) field[x + j][y + k] = col;
		}
		scol = field[sx][sy];
		/*rep(i, h + 1){
			rep(j, w + 1) cout << field[i][j] << " ";
			puts("");
  		}*/
		if(dfs(sx, sy) || field[y][x] != 0) cout << "OK" << endl;
		else cout << "NG" << endl; 
	}
	return 0;
}