#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#pragma region defins
#define ll long long
#define loop(i,n) for (int i = 0; i < n; i++)
#define loops(i,f,n) for (int i = (f); i < n; i++)
#define INF 100000000000000
#define sort(a) sort(a.begin(),a.end())
#define rsort(a) sort(a.rbegin(),a.rend())
using namespace std;
#pragma endregion
int w, h, sx, sy, gx, gy, n;
vector <vector<int > > grid(105, vector<int>(105));
vector <vector<bool > > grid_visited(105, vector<bool>(105, false));
void input(int c, int d, int x, int y)
{
	if (d == 0)//yokonaga
	{
		loop(i, 2)
		{
			loop(j, 4)
			{
				grid[y + i][x + j] = c;
			}
		}
	}
	else//tatenaga
	{
		loop(i, 4)
		{
			loop(j, 2)
			{
				grid[y + i][x + j] = c;
			}
		}
	}
}
bool dfs(int nx, int ny)
{
	if (nx == gx&&ny == gy)return true;
	if (nx < 0 || ny < 0 || nx >= h || ny >= w || grid[nx][ny] == 0 || grid_visited[nx][ny])return false;
	grid_visited[nx][ny] = true;
	return (dfs(nx + 1, ny) || dfs(nx, ny + 1) || dfs(nx - 1, ny) || dfs(nx, ny - 1));
	return false;
}
int main()
{
	while (1)
	{
		cin >> w >> h;
		if (!w && !h) break;
		else
		{
			cin >> sx >> sy >> gx >> gy >> n;
			sx--; sy--; gx--; gy--;
			loop(i, n)
			{
				int c, d, x, y;
				cin >> c >> d >> x >> y;
				x--; y--;
				input(c, d, x, y);
			}
			/*loop(i, h)
			{
				loop(j, w)
				{
					cout << grid[i][j] << " ";
				}
				cout << endl;
			}*/
			cout << (dfs(sx, sy) ? "OK" : "NG") << endl;
		}
	}

}
