#include<iostream>
#include<algorithm>
using namespace std;
int a[100][100],b[100][100];
bool o[100][100];
bool l;
void solve(int w,int h,int xg, int yg,int c,int n,int m) {
	if (m<h-1&&a[n][m+1] == c) {
		b[n][m + 1] = min(b[n][m] + 1, b[n][m + 1]);
		if (n == xg&&m + 1 == yg) {
			l = true; return;
		}
		a[n][m + 1] = 0;
		solve(w,h,xg, yg, c, n, m + 1);
	}
	if (m > 0 && a[n][m - 1] == c) {
		b[n][m - 1] = min(b[n][m] + 1, b[n][m - 1]);
		if (n == xg&&m - 1 == yg) {
			l = true;
			return;
		}
		a[n][m - 1] = 0;
		solve(w, h, xg, yg, c, n, m - 1);
	}
	if (n<w - 1 && a[n+1][m ] == c) {
		b[n+1][m] = min(b[n][m] + 1, b[n+1][m]);
		if (n + 1 == xg&&m == yg) { l = true; return; }
		a[n + 1][m] = 0;
		solve(w, h, xg, yg, c, n+1,m);
	}
	if (n>0 && a[n-1][m] == c) {
		b[n-1][m] = min(b[n][m] + 1, b[n-1][m]);
		if (n == xg&&m == yg) { l = true; return; }
		a[n - 1][m] = 0;
		solve(w, h, xg, yg, c, n-1, m);
	}
}
int main() {
	int w, h;
	while (cin >> w >> h&&w != 0 && h != 0) {
		int xs, ys, xg, yg,n;
		cin >> xs >> ys;
		cin >> xg >> yg;
		cin >> n;
		for (int i = 0; i < w; i++) {
			for (int j = 0; j < h; j++) {
				a[i][j] = 0;
				b[i][j] = 10000;
				o[i][j] = false;
			}
		}
		for (int i = 0; i < n; i++) {
			int c, d, x, y;
			cin >> c >> d >> y >> x;
			if (d == 0) {
				for (int z = 0; z < 2; z++) {
					for (int j = 0; j < 4; j++) 
						a[x + z-1][y + j-1] = c;
				}
			}
			else {
				for (int j = 0; j < 4; j++) {
					for (int z = 0; z < 2; z++) 
						a[x + j-1][y + z-1] = c;
				}
			}
		}
		int k = a[xs-1][ys-1];
		a[xs-1][ys-1] = 0;
		l=false;
		if(k!=0)
			solve(w,h,xg-1, yg-1, k,xs-1,ys-1);
		if (l) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
}