#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

class Point
{
public:
	int x;
	int y;

	Point(int x = 0, int y = 0) : x(x), y(y){}
	bool operator == (const Point& target)
	{
		return (this->x == target.x && this->y == target.y);
	}
};

int w, h;
int map[105][105];
Point start;
Point goal;
int n; //????????????????????°
int c; //???
int d; //??????
Point blockPoint;

void setSideways(const Point& blockPoint)
{
	//?¨??????????????????????map???????????????????????????
	//
	//	????????????	(?????????blockPoint?????????)
	//	????????????
	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 2; ++j)
		{
			map[blockPoint.x + i][blockPoint.y + j] = c;
		}
	}
}

void setPortrait(const Point& blockPoint)
{
	//????????????????????????map???????????????????????????
	//
	//	??????	(?????????blockPoint?????????)
	//	??????
	//	??????
	//	??????
	for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			map[blockPoint.x + i][blockPoint.y + j] = c;
		}
	}
}

bool dfs(Point point, int color) //color????????£????????????????????¨??????
{
	//??¢?´¢??????????????????????????¨??????????????°??????0??????????????????
	map[point.x][point.y] = 0;

	if (point == goal)
	{
		return true;
	}
	//???????????????????????????????????´????????´???????????????????????????????????????
	bool upCase = false;
	bool downCase = false;
	bool leftCase = false;
	bool rightCase = false;
	//?????¨?????°?????????????????????????????????????????°???
	Point upPoint = Point(point.x, point.y - 1);
	Point downPoint = Point(point.x, point.y + 1);
	Point leftPoint = Point(point.x - 1, point.y);
	Point rightPoint = Point(point.x + 1, point.y);

	//??????????????????????????????????????°???????????????????????????????????????????????????
	if (upPoint.y >= 1 && map[upPoint.x][upPoint.y] == color)
	{
		upCase = dfs(upPoint, color);
	}
	if (downPoint.y <= h && map[downPoint.x][downPoint.y] == color)
	{
		downCase = dfs(downPoint, color);
	}
	if (leftPoint.x >= 1 && map[leftPoint.x][leftPoint.y] == color)
	{
		leftCase = dfs(leftPoint, color);
	}
	if (rightPoint.x <= w && map[rightPoint.x][rightPoint.y] == color)
	{
		rightCase = dfs(rightPoint, color);
	}

	return (upCase || downCase || leftCase || rightCase);
}

int main()
{
	while (true)
	{
		//?????????????????????
		for (int i = 0; i < 105; ++i)
		{
			for (int j = 0; j < 105; ++j)
			{
				map[i][j] = 0;
			}
		}

		//??????????????§????????\???
		cin >> w >> h;
		if (w == 0 && h == 0) return 0;

		//??????????????°????????´????????°?????\???
		cin >> start.x >> start.y;
		cin >> goal.x >> goal.y;

		//????????????????????° n ?????\???
		cin >> n;

		//???????????????????????±??\???
		for (int i = 0; i < n; ++i)
		{
			cin >> c >> d >> blockPoint.x >> blockPoint.y;
			if (d == 0)
			{
				setSideways(blockPoint);
			}
			if (d == 1)
			{
				setPortrait(blockPoint);
			}
		}

		int startColor = map[start.x][start.y];
		if (startColor != 0 && dfs(start, startColor))
		{
			cout << "OK" << endl;
		}
		else
		{
			cout << "NG" << endl;
		}
	}
	return 0;
}