#include <iostream>
using namespace std;
int F[102][102];

void DFScolor(int X,int Y,int color){

	if(F[X][Y]!=color)
		return;
	
	F[X][Y]=9;
	DFScolor(X-1,Y,color);
	DFScolor(X,Y+1,color);
	DFScolor(X+1,Y,color);
	DFScolor(X,Y-1,color);
	
}


int main(){
while(1){
	int H,W,xg,yg,xs,ys,n,count=0;
	cin>>H;
	if(H==0)
		count++;
	cin>>W;
	if(W==0)
		count++;
	if(count==2)
		return 0;
	cin>>xs>>ys;
	cin>>xg>>yg;	
	cin>>n;
	int c,d,x,y;
	int xb[n],yb[n],colo[n];
	for(int i=0;i<n;i++){
		
		cin>>c>>d>>x>>y;
		colo[i]=c;
		xb[i]=x;
		yb[i]=y;
		if(d==0){
			for(int o=y;o<y+2;o++){
				for(int j=x;j<x+4;j++){
					F[j][o]=c;
				}
			}
		}
		else if(d==1){
			for(int o=y;o<y+4;o++){
				for(int j=x;j<x+2;j++){
					F[j][o]=c;
				}
			}
		}
		
	}
	
	for(int i=0;i<n;i++){
		if(xb[i]==xs&&yb[i]==ys){
			DFScolor(xb[i],yb[i],colo[i],xg,yg);
			
			break;
		}
	}
	if(F[xg][yg]==9)
		cout<<"OK"<<endl;
	else
		cout<<"NG"<<endl;
	
}
}