#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

bool block[6][110][110];
bool visit[110][110];

int main(){
	int w, h;
	int xs, ys, xg, yg;
	int n, c, d, x, y;
	while(scanf("%d%d%d%d%d%d%d", &w, &h, &xs, &ys, &xg, &yg, &n) == 7){
		memset(block, 0, sizeof block);
		memset(visit, 0, sizeof visit);

		for(int i = 0; i < n; ++i){
			scanf("%d%d%d%d", &c, &d, &x, &y);
			
			int dx, dy;
			if(d){ dx = 2; dy = 4; }
			else{  dy = 2; dx = 4; }

			for(int j = 0; j < dy; ++j)
			for(int k = 0; k < dx; ++k){
				block[c][y + j][x + k] = true;
			}
		}

		for(c = 5; c > 1 && !block[c][ys][xs]; --c);

		if(c){
			queue<int> q;
			q.push(ys << 16 | xs);
			visit[ys][xs] = true;
			while(!q.empty()){
				y = q.front() >> 16;
				x = q.front() & 0xffff;
				q.pop();

				for(int dy = -1; dy <= 1; ++dy)
				for(int dx = -1; dx <= 1; ++dx){
					if(block[c][y+dy][x+dx] && !visit[y+dy][x+dx]){
						visit[y+dy][x+dx] = true;
						q.push(y+dy << 16 | x+dx);
					}
				}
			}
		}

		puts(visit[yg][xg] ? "OK" : "NG");
	}
}
#include <iostream>
#include <string>
using namespace std;

string ans;
int w,h,gx,gy;
int map[110][110];
int dx_[4] = {0,1,0,-1};
int dy_[4] = {1,0,-1,0};
int dx[2][8] = {
	{0,1,2,3,0,1,2,3},
	{0,1,0,1,0,1,0,1}
};
int dy[2][8] = {
	{0,0,0,0,1,1,1,1},
	{0,0,1,1,2,2,3,3},
};
void solve(int x,int y,int color){
	if( ans == "OK" || color == 0 ) return;

	for(int i=0 ; i<4 ; ++i ){
		int mx = x + dx_[i];
		int my = y + dy_[i];
		if( mx<0 || mx>w || my<0 || my>h ) continue;
		
		if( map[my][mx] == color ){
			if( mx == gx && my == gy ){
				ans = "OK";
			}else{
				map[my][mx] = 0;
				solve( mx , my , color );
			}
		}
	}
}

int main(){
	int sx,sy,n;
	
	while( cin >> w >> h , w|h ){
		ans = "NG";
		for(int y=0 ; y<110 ; ++y )
			for(int x=0 ; x<110 ; ++x )
				map[y][x] = 0;

		cin >> sx >> sy >> gx >> gy >> n ;
		for(int i=0 ; i<n ; ++i ){
			int c,d,x,y;
			cin >> c >> d >> x >> y;
			for(int j=0 ; j<8 ; j++){
				int mx = x + dx[d][j];
				int my = y + dy[d][j];
				map[my][mx] = c;
			}
		}
		solve( sx , sy , map[sy][sx] );
		cout << ans << endl;
	}
}