#include <iostream>
using namespace std;

int map[102][102];

void route(int h, int w, int color) {
	if (map[h][w] != color)
		return;
	map[h][w] = 0;
	route(h, w + 1, color);
	route(h + 1, w, color);
	route(h, w - 1, color);
	route(h - 1, w, color);
}


int main() {
	int h, w, xs, ys, xg, yg, n;

	while (1) {
		cin >> h >> w >> xs >> ys >> xg >> yg >> n;
		if (h == 0 && w == 0)
			break;

		int c, d, x, y;
		for (int i = 0; i<n; i++) {
			cin >> c >> d >> x >> y;
			if (d == 0) {
				for (int j = 1; j <= 4; j++)
					map[j + x][y] = map[j + x][y+1] = c;
			}
			else {
				for (int j = 1; j <= 4; j++)
					map[x][y + j] = map[x + 1][y+j] = c;
			}
		}
		int color = map[xs][ys];
		route(xs, ys, color);
		if (xg == 0 && yg == 0)
			cout << "OK" << endl;
		else
			cout << "NG";
	}

	return 0;
}