#include <iostream>
#include <cstring>
using namespace std;

int a;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int board[105][105];

void dfs(int x , int y , int w , int h , int xg , int yg , int c){
	if(x==xg&&y==yg) {
		a=1;
		return;
	}
	for(int i=0;i<4;++i){
		int tx=x+dx[i];
		int ty=y+dy[i];
		if(tx<=0 || ty<=0 || tx>w || ty>h || board[tx][ty]!=c || board[tx][ty]==0 || a ) continue;
		dfs( tx,ty,w,h,xg,yg,c);
	}
}
int main(){
	int w , h;
	while(cin >> w >> h , w||h){
		int xs , ys , xg , yg ;
		int n;
		a=0;
		memset(board,0,sizeof(board));
		cin >> xs >> ys >> xg >> yg >> n;
		for(int i=0;i<n;++i){
			int c , d , x , y;
			cin >> c >> d >> x >> y;
			if(!d){
				for(int k=y;k<y+2;++k){
					for(int j=x;j<x+4;++j){
						board[j][k]=c;
					}
				}
			} else {
				for(int k=y;k<y+4;++k){
					for(int j=x;j<x+2;++j){
						board[j][k]=c;
					}
				}
			}
		}
		int sc=board[xs][ys];
		int gc=board[xg][yg];
		if(sc!=gc) {
		}
		else dfs( xs , ys , w , h , xg , yg , sc);
		cout << ( a ? "OK" : "NG") << endl;
	}
	return 0;
}