#include<iostream>
#include<algorithm>

using namespace std;

int board[101][101],w,h;
bool visited[101][101];
int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

bool search(int x,int y,int tarx,int tary,int c)
{
	visited[y][x]=true;
	if(board[y][x]!=c)		return false;
	if(x==tarx && y==tary)	return true;
	
	for(int k=0;k<4;k++){
		int xx=x+dx[k],yy=y+dy[k];
		if(xx<=0 || w<xx || yy<=0 || h<yy)	continue;
		if(!visited[yy][xx] && search(xx,yy,tarx,tary,c))	return true;
	}
	return false;
}

int main()
{
	for(;cin>>w>>h,w;){
		for(int i=1;i<=h;i++)for(int j=1;j<=w;j++)board[i][j]=-1,visited[i][j]=false;
		int xs,ys,xg,yg,n;	cin>>xs>>ys>>xg>>yg>>n;
		while(n--){
			int c,d,x,y;	cin>>c>>d>>x>>y;
			for(int i=0;i<(d?4:2);i++)for(int j=0;j<(d?2:4);j++)board[y+i][x+j]=c;
		}

		if(board[ys][xs]!=board[yg][xg])	cout<<"NG"<<endl;
		else	cout<<(search(xs,ys,xg,yg,board[ys][xs])?"OK":"NG")<<endl;
	}

	return 0;
}