#include <iostream>
using namespace std;

char F[102][102];

void Block(int c,int d,int x,int y){
	if(d==0){
    	for(int i=0;i<4;i++){
    		F[y  ][x+i]=c;
			F[y+1][x+i]=c;
    	}
  	}else{
    	for(int i=0;i<4;i++){
    		F[y+i][x  ]=c;
    		F[y+i][x+1]=c;
    	}
	}
}
void DFS(int y,int x,int c){
	if(F[y][x]!=c)
		return;

	F[y][x] = 6;

    DFS(y-1,x  ,c);
    DFS(y  ,x+1,c);
    DFS(y+1,x  ,c);
    DFS(y  ,x-1,c);
}
int main(){
	while(true){
		int w,h,xs,ys,xg,yg,n;
		cin >> w >> h;
		if(w==0&&h==0){break;}
		for(int i=0;i<h;i++){
			for(int k=0;k<w;k++){
				F[i][k]=-1;
			}
		}
		cin >> xs >> ys;
		cin >> xg >> yg;
		cin >> n;
		for(int i=0; i<n; i++){
			int c,d,x,y;
			cin >> c >> d >> x >> y;
			Block(c,d,x,y);
  		}
 		DFS(ys,xs,F[ys][xs]);
		if(F[yg][xg]==6){
			cout << "OK" << endl;
		}else{
			cout << "NG" << endl;
		}
	}
  return 0;
}
