#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
using namespace std;
int field[128][128];
int dx[] = {-1,0,0,1},dy[] = {0,-1,1,0};
int w,h;
void func(int x,int y,int c){
	if(x < 0 || y < 0 || x >= w || y >= h)return ;
	if(field[y][x] == -1 || field[y][x] == 0)return ;
	if(field[y][x] != c)return ;
	field[y][x] = -1;
	for(int i = 0; i < 4; i++){
		func(x+dx[i],y+dy[i],c);
	}
}
int main(){
	while(scanf("%d%d",&w,&h),w,h){
		int xs,ys,xg,yg,n;
		memset(field,0,sizeof(field));
		scanf("%d%d%d%d%d",&xs,&ys,&xg,&yg,&n);
		for(int i = 0; i < n; i++){
			int c,d,x,y;
			scanf("%d%d%d%d",&c,&d,&x,&y);
			if(d == 0){
				for(int j = x; j < x + 4; j++){
					field[y][j] = c;
					field[y+1][j] = c;
				}
			}
			else{
				for(int j = y; j < y + 4; j++){
					field[j][x] = c;
					field[j][x+1] = c;
				}
			}
		}
		func(xs,ys,field[ys][xs]);
		cout << (field[yg][xg]==-1?"OK":"NG") << endl;
	}
	return 0;
}