#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, n) for(int i = 1; i <= n; ++i)
#define INF 0
#define MAX 102

using namespace std;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
 
int field[102][102];
int h, w, sx, sy, gx, gy, n;
int col, dire, x, y;
int scol;

bool dfs(int nx, int ny) {
	if(nx == gx && ny == gy) return true;
	field[nx][ny] = -1;
	for(int i = 0; i < 4; ++i) {
		int nex = nx + dx[i];
		int ney = ny + dy[i];
		if(0 < nex && nex <= w && 0 < ney && ney <= h && scol == field[nex][ney]) {
			if(dfs(nex, ney)) return true;
		}
	}
	return false;
}

int main() {
	while(1) {
		scol = INF;
		cin >> h >> w;
		for(int i = 1; i <= h; ++i) {
			for(int j = 1; j <= w; ++j) {
				field[i][j] = 0;
			}
		}
		if(h == 0 && w == 0) break;
		cin >> sx >> sy >> gx >> gy;
		cin >> n;
		rep(k, n) {
			cin >> col >> dire >> x >> y;
			if(dire == 1) {
				for(int i = 0; i < 4; ++i) {
					for(int j = 0; j < 2; ++j) field[x+j][y+i] = col;
				}a
			}
			else {
				for(int i = 0; i < 2; ++i) {
					for(int j = 0; j < 4; ++j) field[x+j][y+i] = col;
				}
			}
		}
		scol = field[sx][sy];
		if(dfs(sx, sy)) cout << "OK" << endl;
		else cout << "NG" << endl; 
	}
	return 0;
}