#include<iostream>
using namespace std;


int F[1000][1000];

//?????????????????????
void r(int yy,int xx,int z){
 if(F[yy][xx]!=z){
	return ;
 }

F[yy][xx]=10;

r(yy-1,xx,z);
r(yy,xx+1,z);
r(yy+1,xx,z);
r(yy,xx-1,z);

}




int main(){
 int w,h,xs,ys,xg,yg,n;
 int c,d,x,y;

while(1){
 cin>>w>>h;

//?????????????????????0???????????????
 if(w==0&&h==0)break;
//???????????????????????????????????\?????°????±??????£???????????????
 cin>>xs>>ys>>xg>>yg>>n;

//n?????°???????????????????????????
for(int i=0;i<n;i++){
	cin>>c>>d>>x>>y;//?????????????????¨????????±????????????
	if(d==0){
		F[x  ][y]=c;
		F[x+1][y]=c;
 		F[x+2][y]=c;
 		F[x+3][y]=c;
 		F[x  ][y+1]=c;
 		F[x+1][y+1]=c;
 		F[x+2][y+1]=c;
 		F[x+3][y+1]=c;
	}
	if(d==1){
		F[x][y  ]=c;
 		F[x][y+1]=c;
		F[x][y+2]=c;
		F[x][y+3]=c;
 		F[x+1][y  ]=c;
		F[x+1][y+1]=c;
		F[x+1][y+2]=c;
 		F[x+1][y+3]=c;
	}
}

//??\????????????????????????


//??????????????????
r(xs,ys,F[xs][ys]);
//??´???????????????
if(F[xg][yg]==10){
	cout<<"OK"<<endl;
}else{
	cout<<"NG"<<endl;
}
//???????????????????????????
for(int i=1;i<=w;i++){
	for(int g=1;g<=w;g++){
		F[i][g]=6;
	}
}
//?????????????????????
}
return 0;
}





	