#include <iostream>
int m[101][101],w,h,r,gx,gy;
void dfs(int x,int y,int c){
	if(!(x-gx)&&!(y-gy))r=1;
	if(x>1&&m[x-1][y]==c)m[x-1][y]=0,dfs(x-1,y,c);
	if(x<=w&&m[x+1][y]==c)m[x+1][y]=0,dfs(x+1,y,c);
	if(y>1&&m[x][y-1]==c)m[x][y-1]=0,dfs(x,y-1,c);
	if(y<=h&&m[x][y+1]==c)m[x][y+1]=0,dfs(x,y+1,c);
	return ;
}

int main(){
	//whÍ{[hÌå«³AnÍubNÌÂ
	int n,c,d,sx,sy,bx,by;
	
	while(std::cin>>w>>h,w&&h){
		for(int y=0;y<101;y++){
			for(int x=0;x<101;x++){
				m[x][y] = 0;
			}
		}
		r=0;
		std::cin>>sx>>sy;
		std::cin>>gx>>gy;
		std::cin>>n;
		for(int i=0;i<n;i++){
			std::cin>>c>>d>>bx>>by;
			int bw,bh;
			if(d)bw=2,bh=4;
			else{bh=2,bw=4;}
			for(int y=by;y<=by+bh;y++){
				for(int x=bx;x<=bx+bw;x++){
					m[x][y] = c;
				}
			}
		}
		if(m[sx][sy])c = m[sx][sy],m[sx][sy]=0,dfs(sx,sy,c);
		if(r)std::cout<<"OK"<<std::endl;
		else{std::cout<<"NG"<<std::endl;}
	}
	return 0;
}