#include <iostream>
#include <vector>
#include <queue>

using namespace std;
int dx[2][8] = { { 0, 1, 2, 3, 0, 1, 2, 3 }, { 0, 1, 0, 1, 0, 1, 0, 1 } };
int dy[2][8] = { { 0, 0, 0, 0, 1, 1, 1, 1 }, { 0, 0, 1, 1, 2, 2, 3, 3 } };

int dx2[4] = {1, 0, -1, 0};
int dy2[4] = {0, -1, 0, 1};

struct Point
{
	int x, y;
	Point(){};
	Point(int a, int b)
	{
		x = a;
		y = b;
	}
};

void solve()
{
	int w, h;
	while (cin >> w >> h, w || h)
	{
		vector< vector<int> > field(h + 1, vector<int>(w + 1));
		Point start, goal;
		cin >> start.x >> start.y >> goal.x >> goal.y;
		int n;
		cin >> n;
		for (int i = 0; i < n; ++i)
		{
			int c, d;
			Point p;
			cin >> c >> d >> p.x >> p.y;
			for (int j = 0; j < 8; ++j)
			{
				int nextX = p.x + dx[d][j];
				int nextY = p.y + dy[d][j];
				field[nextY][nextX] = c;
			}
		}
		if (field[start.y][start.x] != field[goal.y][goal.x])
		{
			cout << "NG" << endl;
			continue;
		}
		queue<Point> que;
		que.push(start);
		bool isOK = false;
		deque< deque<bool> > isUsed(h + 1, deque<bool>(w + 1));
		isUsed[start.y][start.x] = true;
		while (!que.empty())
		{
			Point p = que.front();
			que.pop();
			if (p.x == goal.x && p.y == goal.y)
			{
				isOK = true;
				break;
			}
			for (int i = 0; i < 4; ++i)
			{
				int nx = p.x + dx2[i];
				int ny = p.y + dy2[i];
				
				if ((1 <= nx && nx <= w) && (1 <= ny && ny <= h) && field[ny][nx] == field[start.y][start.x] && isUsed[ny][nx] == false)
				{
					isUsed[ny][nx] = true;
					que.push(Point(nx, ny));
				}
			}
		}
		if (isOK)
		{
			cout << "OK" << endl;
		}
		else
		{
			cout << "NG" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}