#include <iostream>
using namespace std;

int n, w, h, xs, ys, xg, yg, f[105][105] = { 0 }, dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 }, used[105][105] = { 0 };
bool flag;
void dfs(int y, int x) {
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (xg == nx&&yg == ny) {
			flag = true;
			return;
		}
		if (used[ny][nx]) continue;
		if (1 <= nx&&nx <= w && 1 <= ny&&ny <= h&&f[ny][nx]>0) {
			used[ny][nx] = 1;
			dfs(ny, nx);
		}
	}
	return;
}

int main() {
	while (1) {
		flag = false;
		cin >> w >> h;
		if (w == 0 && h == 0) return 0;
		cin >> xs >> ys >> xg >> yg >> n;
		for (int i = 0; i < n; i++) {
			int c, d, x, y;
			cin >> c >> d >> x >> y;
			if (d == 0) {
				for (int j = 0; j < 2; j++) {
					for (int k = 0; k < 4; k++) {
						f[y + j][x + k] = 1;
					}
				}
			}
			else {
				for (int j = 0; j < 4; j++) {
					for (int k = 0; k < 2; k++) {
						f[y + j][x + k] = 1;
					}
				}
			}
		}
		used[ys][xs] = 1;
		dfs(ys, xs);
		if (flag) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
}