#include <iostream>
#include <stdio.h>
#include <queue>
using namespace std;
class node{
public:
	int x,y;
	void set(int xx,int yy){
		x = xx;
		y = yy;
	}
	bool check(int w,int h){
		if(x>=0&&y>=0){
			if(x<=w&&y<=h) return true;
		}
		return false;
	}
	
};

int main(){
	int w,h;
	while(1){
		//printf("w:%d,h:%d\n",w,h);
		int xs,ys,xg,yg,n,c,dir,x,y;
		int i,j;
		int color[101][101];
		int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
		bool visited[101][101];
		queue<node> q;
		node a;
		scanf("%d%d",&w,&h);
		if(w==0&&h==0) break;
		scanf("%d%d",&xs,&ys);
		scanf("%d%d",&xg,&yg);
		scanf("%d",&n);
	
		while(n--){
			scanf("%d%d%d%d",&c,&dir,&x,&y);
			if(dir==0){
				for(i=0;i<2;i++){
					for(j=0;j<4;j++) color[x+j][y+i] = c;
				}
			}
			else{
				for(i=0;i<2;i++){
					for(j=0;j<4;j++) color[x+i][y+j] = c;
				}
			}
		}
		a.set(xs,ys);
		q.push(a);
		visited[a.x][a.y]=true;
		while(!q.empty()){
			a = q.front();
			q.pop();
			for(int i=0;i<4;i++){
				a.x += dx[i];
				a.y += dy[i];
				if(!a.check(w,h)&&(color[xs][ys]==color[a.x][a.y])&&!visited[a.x][a.y]){
					q.push(a);
					if(a.x==xg&&a.y==yg) break;
					visited[a.x][a.y] = true;
				}
			}
		}
		if(visited[xg][yg]) printf("OK\n");
		else printf("NG\n");
	}

	return 0;
}