#include<iostream>
using namespace std;
int w, h, xs, ys, xg, yg, stage[101][101];
int ny[4] = { 0, 1, 0, -1 }, nx[4] = { 1, 0, -1, 0 };
int bc;
bool ans = false;
void func(int x, int y, int lastp){
	if (x == xg && y == yg){
		ans = true;
	}
	for (int i = 0; i < 4; i++){
		if (stage[y + ny[i]][x + nx[i]] != bc || i == lastp) return;
		func(x + nx[i], y + ny[i], (i + 2) % 4);
	}
}
int main(){
	int n, c, d, x, y, bw, bh;
	while (1){
		for (int i = 0; i < 101; i++){
			for (int j = 0; j < 101; j++){
				stage[i][j] = 0;
			}
		}
		cin >> w >> h;
		if (w == 0 && h == 0) return 0;
		cin >> xs >> ys >> xg >> yg >> n;
		for (int i = 0; i < n; i++){
			cin >> c >> d >> x >> y;
			if (d == 0){
				bw = 4;
				bh = 2;
			}
			else{
				bw = 2;
				bh = 4;
			}
			for (int j = 0; j < bh; j++){
				for (int k = 0; k < bw; k++){
					stage[y + j][x + k] = c;
				}
			}
		}
		bc = stage[ys][xs];
		if (bc == 0){
			cout << "NG\n";
			continue;
		}
		func(1, 1, -1);
		if (ans == true) cout << "OK\n";
		else cout << "NG\n";
	}
	return 0;
}