#include <iostream>
using namespace std;
int board[100][100],w,h,xg,yg;
bool f(int y,int x){
	board[y][x] = 0;
	int dy[] = {-1,0,0,1},dx[] = {0,-1,1,0},i;
	if(y == yg - 1 && x == xg -1) return true;
	for(i = 0;i < 4;i++){
		if(y + dy[i] > -1 && y + dy[i] < h && x + dx[i] > -1 && x + dx[i] < w){
			if(board[y+dy[i]][x+dx[i]] == 2){
				if(f(y+dy[i],x+dx[i])) return true;
			}
		}
	}
	return false;
}
int main(){
	int xs,ys,n,i,c,d,x,y,j,k;
	while(cin >> w >> h && (w != 0 && h != 0)){
		cin >> xs >> ys;
		cin >> xg >> yg;
		cin >> n;
		for(i = 0;i < n;i++){
			cin >> c >> d >> x >> y;
			x -= 1;
			y -= 1;
			if(d == 0){
				for(j = 0;j < 2;j++){
					for(k = 0;k < 4;k++){
						board[y+j][x+k] = c;
					}
				}
			}
			else if(d == 1){
				for(j = 0;j < 2;j++){
					for(k = 0;k < 4;k++){
						board[y+k][x+j] = c;
					}
				}
			}
		}
		if(board[y - 1][x - 1] == 2){
			if(f(ys - 1,xs -1)) cout << "OK" << endl;
			else cout << "NG" << endl;
		}
		else cout << "NG" << endl;
		for(j = 0;j < 100;j++){
			for(i = 0;i < 100;i++){
				board[j][i] = 0;
			}
		}
	}
	return 0;
}