#include <bits/stdc++.h>

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define MAX 101

using namespace std;

int field[MAX][MAX];
bool went[MAX][MAX];
int w, h;
int sx, sy, gx, gy;
int scol;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

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

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