#include<stdio.h>
int a[103][103],gx,gy;
bool f(int sx,int sy,int c)
{
	if(sx==gx&&sy==gy)return true;
	if(a[sy][sx]!=c)return false;
	a[sy][sx]=0;
	if(f(sx+1,sy,c)||f(sx-1,sy,c)||f(sx,sy+1,c)||f(sx,sy-1,c))return true;
	return false;
}
int main()
{
	int h,w,sx,sy,n,i,j,c,d,x,y,
		dx[2][8]={{0,1,2,3,0,1,2,3},{0,0,0,0,1,1,1,1}},
		dy[2][8]={{0,0,0,0,1,1,1,1},{0,1,2,3,0,1,2,3}};
	while(scanf("%d%d",&w,&h),h)
	{
		scanf("%d%d%d%d%d",&sx,&sy,&gx,&gy,&n);
		for(i=0;i<103;++i)for(j=0;j<103;++j)a[i][j]=0;
		while(n--)
		{
			scanf("%d%d%d%d",&c,&d,&x,&y);
			for(i=0;i<8;++i) a[y+dy[d][i]][x+dx[d][i]]=c;
		}
		if(a[sy][sx]&&f(sx,sy,a[sy][sx]))puts("OK");
		else puts("NG");
	}
	return 0;
}