#include <cstdio>
#include <string.h>
using namespace std;

int map[200][200];
bool reach[200][200];
int w, h;

typedef struct {
	int x;
	int y;
} SIZE;

SIZE size[2] = {
	{4, 2}, {2, 4}
};

int angle[][2] = {
	{-1, 0}, {0, -1}, {1, 0}, {0, 1}
};

void search(int x, int y)
{
	if (map[x][y] == 0 || x <= 0 || x > w || y <= 0 || y > h){
		return;
	}
	
	reach[x][y] = true;
	
	for (int i = 0; i < 4; i++){
		if (
		reach[x + angle[i][0]][y + angle[i][1]] == false &&
		map[x + angle[i][0]][y + angle[i][1]] == map[x][y]
		){
//			reach[x + angle[i][0]][y + angle[i][1]] = true;
			search(x + angle[i][0], y + angle[i][1]);
		}
	}
}
		

int main()
{
	while (scanf("%d %d", &w, &h), w + h){
		memset(map, 0, sizeof(map));
		memset(map, 0, sizeof(reach));
		
		int xs, ys;
		scanf("%d %d", &xs, &ys);
		
		int xg, yg;
		scanf("%d %d", &xg, &yg);
		
		int n;
		scanf("%d", &n);
		for (int i = 0; i < n; i++){
			int c, d, x, y;
			scanf("%d %d %d %d", &c, &d, &x, &y);
			
			for (int j = 0; j < size[d].y; j++){
				for (int k = 0; k < size[d].x; k++){
					map[x + k][y + j] = c;
				}
			}
		}
/*		
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				printf("%d ", map[j][i]);
			}
			puts("");
		}
*/		
		search(xs, ys);
/*		
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				printf("%d ", reach[j][i]);
			}
			puts("");
		}
*/		
		if (reach[xg][yg]){
			printf("OK\n");
		}
		else {
			printf("NG\n");
		}
	}
	
	return 0;
}