#include<iostream>
#include<algorithm>
using namespace std;
int field[101][101],b[101][101],X,Y,n,dx[4]={0,1,0,-1},dy[4]={1,0,-1,0},I,sX,sY,gX,gY,ans=-1,sgc;
int func(int x,int y){
	for(I=0;I<4;I++){
		int xx=x+dx[I];
		int yy=y+dy[I];
		if(xx>0&&yy>0&&xx<=X&&yy<=Y&&field[xx][yy]==sgc&&b[xx][yy]==0){
			if(xx==gX&&yy==gY){
				if(ans==-1)ans=b[x][y];
				else ans=min(b[x][y]+1,ans);
			}
			else{
			b[xx][yy]=b[x][y]+1;
			func(xx,yy);
			}
		}
	}
	return 0;
}
int main(){
	int i,i2,c,d,x,y;
	cin>>X>>Y;
	while(X!=0){
		cin>>sX>>sY>>gX>>gY>>n;
		ans=-1;
		for(i=1;i<=100;i++){
			c=0;
			d=0;
			x=0;
			y=0;
			for(i2=1;i2<=100;i2++){
				field[i][i2]=0;
			}
		}
		for(i=1;i<=n;i++){
			cin>>c>>d>>x>>y;
			if(d==0){
				field[x][y]=c;
				field[x+1][y]=c;
				field[x+2][y]=c;
				field[x+3][y]=c;
				field[x][y+1]=c;
				field[x+1][y+1]=c;
				field[x+2][y+1]=c;
				field[x+3][y+1]=c;
			}
			else{
				field[x][y]=c;
				field[x][y+1]=c;
				field[x][y+2]=c;
				field[x][y+3]=c;
				field[x+1][y]=c;
				field[x+1][y+1]=c;
				field[x+1][y+2]=c;
				field[x+1][y+3]=c;
			}
		}
		/*for(i=1;i<=Y;i++){
			for(i2=1;i2<=X;i2++)cout<<field[i2][i];
			cout<<endl;
		}*/
		sgc=field[sX][sY];
		func(sX,sY);
		if(ans==-1)cout<<"NG"<<endl;
		else cout<<"OK"<<endl;
		cin>>X>>Y;
	}
}