#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){
	if (x == xg && y == yg){
		ans = true;
	}
	for (int i = 0; i < 4; i++){
		if (stage[y + ny[i]][x + nx[i]] != bc) return;
		func(x + nx[i], y + ny[i]);
	}
}
int main(){
	int n, c, d, x, y, bw, bh;
	cin >> w >> h >> 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[1][1];
	func(1, 1);
	if (ans == true) cout << "OK\n";
	else cout << "NG\n";
	return 0;
}