#include <iostream>
#include <queue>

using namespace std;

int board[102][102];
bool visited[102][102];

int w, h, xg, yg;

class Point{
public:
	int x, y;

	Point(int xx, int yy){
		x = xx;
		y = yy;
	}
};

const int UNDEFINED = 0;
bool judge(int, int);
int main(void){
	const int BLOCK_WIDTH = 2;
	const int BLOCK_HEIGHT = 4;

	for(int i = 0; i < 102; i ++)
		for(int j = 0; j < 102; j ++){
			board[i][j] = UNDEFINED;
			visited[i][j] = false;
		}	
	for(int xs, ys, n; cin >> w >> h >> xs >> ys >> xg >> yg >> n, w, h;){
		for(int i = 1; i <= w; i ++){
			for(int j = 1; j <= h; j ++){
				board[j][i] = UNDEFINED;
				visited[j][i] = false;
			}
		}

		while(n --){
			int c, d, x, y; cin >> c >> d >> x >> y;
			
			int width = (!d) ? BLOCK_HEIGHT:BLOCK_WIDTH;
			int height = (!d) ? BLOCK_WIDTH:BLOCK_HEIGHT;

			for(int curX = x; curX <= x + width; curX ++)
				for(int curY = y; curY <= y + height; curY ++)
					board[curX][curY] = c;
		}
		cout << ((judge(xs, ys)) ? "OK":"NG") << endl;
	}

	return 0;
}

bool judge(int firstX, int firstY){
	queue<Point> q; Point p(firstX, firstY);
	q.push(p);
	visited[firstY][firstX] = true;

	int targetColor = board[firstY][firstX];
	if(targetColor == UNDEFINED) return false;
	
	while(!q.empty()){
		if(visited[yg][xg]) return true;
		Point currentNode = q.front(); q.pop();

		for(int delta = -1; delta <= 1; delta += 2){
			for(int a = 0; a < 2; a ++){
				Point nextNode(currentNode.x + ((a)?delta:0), currentNode.y + ((a)?0:delta));

				if(!visited[nextNode.y][nextNode.x] && board[nextNode.y][nextNode.x] == targetColor){
					q.push(nextNode);
					visited[nextNode.y][nextNode.x] = true;
				}
			}
		}
	}

	return false;
}