#include <iostream>
#include <queue>

using namespace std;

struct P {
	int x, y;
};

int main() {
	int W, H;
	while ( cin >> W >> H, W || H ) {
		int sx, sy; cin >> sx >> sy; --sx, --sy;
		int gx, gy; cin >> gx >> gy; --gx, --gy;
		int n; cin >> n;
		int m[5][100][100] = {0};
		for (int i = 0; i < n; ++i) {
			int c, d, X, Y; cin >> c >> d >> X >> Y; --X, --Y, --c;
			int w, h;
			if (d == 0) w = 4, h = 2;
			else w = 2, h = 4;
			for (int y = 0; y < h; ++y) {
				for (int x = 0; x < w; ++x) {
					m[c][Y+y][X+x] = 1;
				}
			}
		}
		int c = -1;
		for (int i = 0; i < 5; ++i) {
			if (m[i][gy][gx]) c = i;
		}
		bool ans = false;
		if (c > -1) {
			queue<P> Q; Q.push( (P){sx, sy} );
			while ( !Q.empty() ) {
				P p = Q.front(); Q.pop();
				if (p.x < 0 || p.x >= W || p.y < 0 || p.y >= H) continue;
				if (!m[c][p.y][p.x]) continue;
				m[c][p.y][p.x] = 0;

				if (p.x == gx && p.y == gy) {
					ans = true;
					break;
				}

				Q.push( (P){p.x+1, p.y} );
				Q.push( (P){p.x-1, p.y} );
				Q.push( (P){p.x, p.y+1} );
				Q.push( (P){p.x, p.y-1} );
			}
		}
		if (ans) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
}