#include<iostream>
using namespace std;

int F[102][102];

bool DFS(int X, int Y, int Xg, int Yg, int c){
	if(F[Y][X] != c){
		return false;
	}else if(F[Y][X] == c && X == Xg && Y == Yg){
		return true;
	}
	F[Y][X] = -1;
	if(DFS(X, Y - 1, Xg, Yg, c)){
		return true;
	}else if(DFS(X + 1, Y, Xg, Yg, c)){
		return true;
	}else if(DFS(X, Y + 1, Xg, Yg, c)){
		return true;
	}else if(DFS(X - 1, Y, Xg, Yg, c)){
		return true;
	}
	
	return false;
}

int main(){
bool isfirst = true;
while(true){
	if(isfirst){
		isfirst = false;
	}else{
		cout << endl;
	}
	int w, h;
	cin >> w >> h;
	if(w == 0 && h == 0){
		break;
	}
	int xs, ys, xg, yg;
	cin >> xs >> ys >> xg >> yg;
	int n;
	cin >> n;
	
	for(int i = 0; i < n; i++){
		int c, d, x, y;
		cin >> c >> d >> x >> y;
		if(d == 0){
			for(int X = x; X < x + 4; X++){
				for(int Y = y; Y < y + 2; Y++){
					F[Y][X] = c;
				}
			}
		}else if(d == 1){
			for(int X = x; X < x + 2; X++){
				for(int Y = y; Y < y + 4; Y++){
					F[Y][X] = c;
				}
			}
		}
	}
	if(DFS(xs, ys, xg, yg, F[xg][yg])){
		cout << "OK";
	}else{
		cout << "NG";
	}
}
	return 0;
}