#include <iostream>
using namespace std;

int F[102][102];
int xg,yg;

void Maze(int X,int Y,int C){
	if(F[X][Y]!=C)
		return;

	if(X==xg&&Y==yg)
		cout << "OK"<<endl;
		return;


	F[X][Y]='.';

	Maze(X-1,Y  ,C);
	Maze(X  ,Y+1,C);
	Maze(X+1,Y  ,C);
	Maze(X  ,Y-1,C);

	cout <<"NG"<<endl;
	
}



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

		cin >>w>>h;
		cin >>xs>>ys;
		cin >>xg>>yg;
		cin >>n;


		if(w==0&&h==0)
			return 0;

		int N=0;
		while(N<n){
			cin >>c>>d>>x>>y;
			if(d==1){
				for(int i=x; i<x+2; i++)
					for(int j=y; j<y+4; j++)
						F[i][j]=c;
			}else{
				for(int i=x; i<x+4; i++)
					for(int j=y; j<y+2; j++)
						F[i][j]=c;
			}
			N++;
		}
			//for(int i=1; i<=h; i++){
					//for(int j=1; j<=w; j++){
						//cout <<F[j][i];
					//}
				//cout << endl;
			//}
		

		Maze(xs,ys,F[xs][ys]);

	}

}