#include<iostream>
using namespace std;

char F[102][102];

void DFS(int Y,int X,char C){
	if(F[Y][X]!=C)
		return;

	F[Y][X]='.';
	
	DFS(Y-1,X,C);
	DFS(Y,X+1,C);	
	DFS(Y+1,X,C);
	DFS(Y,X-1,C);

}


int main(){
while(1){
	int w,h;
	cin>>w>>h;
	if(w==0&&h==0)
		break;
	
	int xs,ys,xg,yg;
	cin>>xs>>ys>>xg>>yg;
	int n;
	cin>>
#include<iostream>
using namespace std;

char F[102][102];

void DFS(int Y,int X,char C){
	if(F[Y][X]!=C)
		return;

	F[Y][X]='.';
	
	DFS(Y-1,X,C);
	DFS(Y,X+1,C);	
	DFS(Y+1,X,C);
	DFS(Y,X-1,C);

}


int main(){
while(1){
	int w,h;
	cin>>w>>h;
	if(w==0&&h==0)
		break;
	
	int xs,ys,xg,yg;
	cin>>xs>>ys>>xg>>yg;
	int n;
	cin>>n;
	char C;
	for(int i=0;i<n;i++){
		int d,x,y;
		char c;
		cin>>c;
		cin>>d>>x>>y;
		if(d==0){
			for(int j=0;j<2;j++){
				for(int l=0;l<4;l++){
					F[y+j][x+l]=c;
				}
			}
		}else{
			for(int j=0;j<4;j++){
				for(int l=0;l<2;l++){
					F[y+j][x+l]=c;
				}
			}
		}
	}
	C=F[ys][xs];
	if(C!=0){
		DFS(ys,xs,C);
		if(F[yg][xg]=='.'&&F[ys][xs]=='.'){
			cout<<"OK"<<endl;
		}else{
			cout<<"NG"<<endl;
		}
	}else{
		cout<<"NG"<<endl;
	}
	
	
}
return 0;
}n;
	char C;
	for(int i=0;i<n;i++){
		int d,x,y;
		char c;
		cin>>c;
		cin>>d>>x>>y;
		if(d==0){
			for(int j=0;j<2;j++){
				for(int l=0;l<4;l++){
					F[y+j][x+l]=c;
				}
			}
		}else{
			for(int j=0;j<4;j++){
				for(int l=0;l<2;l++){
					F[y+j][x+l]=c;
				}
			}
		}
	}
	C=F[ys][xs];
	if(C!=0){
		DFS(ys,xs,C);
		if(F[yg][xg]=='.'&&F[ys][xs]=='.'){
			cout<<"OK"<<endl;
		}else{
			cout<<"NG"<<endl;
		}
	}else{
		cout<<"NG"<<endl;
	}
	
	
}
return 0;
}