#include <iostream>
using namespace std;

char F[101][101];

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;
		cin>>w>>h;
		if(w==0&&h==0){break;}
		int xs,ys;
		cin>>xs>>ys;
		int xg,yg;
		cin>>xg>>yg;
		int n;
		cin>>n;
		int c,d,x,y;
		for(int i=0;i<n;i++){
			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;
}
