#include <iostream>
using namespace std;

char B[102][102];
bool isOK = false;
void setBlock(int c,int d,int x,int y){
	char Cl = '\0';
	switch(c){
		case 1:Cl='W';break;
		case 2:Cl='Y';break;
		case 3:Cl='G';break;
		case 4:Cl='B';break;
		case 5:Cl='R';break;
	}
	if(d == 0){
		for(int i = x; i <= x+3;i++){
			for(int  j = y;j <= y+1;j++){
				B[i][j] = Cl;
			}
		}
	}else{
		for(int i = x; i <= x+1;i++){
			for(int  j = y;j <= y+3;j++){
				B[i][j] = Cl;
			}
		}
	}
}

void Check(int x, int y,int xG,int yG,char c){
	if(B[x][y] != c || isOK){
		return;
	}
	B[x][y] = '.';
	if(x == xG && y == yG){
		isOK=true;
		return;
	}	
	Check(x  ,y-1,xG,yG,c);
	Check(x+1,y  ,xG,yG,c);
	Check(x  ,y+1,xG,yG,c);
	Check(x-1,y  ,xG,yG,c);
}

int main(){
	int W,H,xS,yS,xG,yG,n;
	while(cin >> W >> H){
		isOK=false;
		if(W == 0 && H == 0){
			break;
		}
		cin >> xS >> yS >> xG >> yG >> n;		
		for(int i = 0;i < n;i++){
			int c,d,x,y;
			cin >> c >> d >> x >> y;
			setBlock(c,d,x,y);
		}
		Check(xS,yS,xG,yG,B[xS][yS]);
		if(isOK){
			cout << "OK\n";
		}else{
			cout << "NG\n";
		}
	}
	return 0;
}
