#include <iostream>
using namespace std;

int w,h;
int field[104][104];
int gx,gy;
int sc;

void init()
{
	for(int i=0;i<104;i++){
		for(int j=0;j<104;j++){
			field[i][j] = 0;
		}
	}
}
bool search(int x,int y)
{
	bool flag = false;
	if(x == gx && y == gy)
		flag = true;
	else{
		int vectorx[4] = {-1,0,1,0},vectory[4] = {0,-1,0,1};
		for(int i=0;i<4;i++){
			if(x+vectorx[i] >= 0 && y+vectory[i] >= 0 && x+vectorx[i] < w && y+vectory[i] < h){
				if(field[x+vectorx[i]][y+vectory[i]] == sc){
					field[x][y] = -1;
					flag |= search(x+vectorx[i],y+vectory[i]);
				}
			}
		}
	}
	return flag;
}
int main()
{
	while(cin >> w >> h){
		if(w == 0 && h == 0)
			break;
		init();
		int sx,sy;
		cin >> sx >> sy;
		cin >> gx >> gy;
		int n,c,x,y;
		bool d;
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> c >> d >> x >> y;
			int vectorx,vectory;
			if(d == 0){
				vectorx = 4;vectory = 2;
			}else{
				vectorx = 2;vectory = 4;
			}
			for(int j=0;j<vectorx;j++){
				for(int k=0;k<vectory;k++){
					field[x+j][y+k] = c;
				}
			}
		}
		sc = field[sx][sy];
		if(field[sx][sy] == 0 || field[gx][gy] == 0)
			cout << "NG" << endl;
		else{
			if(search(sx,sy))
				cout << "OK" << endl;
			else
				cout << "NG" << endl;
		}
	}
	return 0;
}