#include<iostream>
using namespace std;


int F[500][500];

//?????????????????????
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);

}

void yoko(int c,int x,int y){
 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+2][y+1]=c;
 F[x+3][y+1]=c;
 F[x+4][y+1]=c;
return ;
}
void tate(int c,int x,int y){
 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;
return ;
}

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)yoko(c,x,y);
	if(d==1)tate(c,x,y);
}

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

//??????????????????
r(xs,ys,F[xs][ys]);
//??´???????????????
if(F[xg][yg]==10){
	cout<<"OK"<<endl;
}else{
	cout<<"NG"<<endl;
}
//?????????????????????
}
return 0;
}





	