#include <bits/stdc++.h>
using namespace std;

int main(){
	int w, h, xs, ys, xg, yg, n, c, d, x, y, color;
	vector< vector< int > > field;
	queue< complex< int > > que;
	bool exist;
	
	while(cin >> w >> h, w){
		cin >> xs >> ys >> xg >> yg >> n;
		
		field.resize(w);
		for(int i = 0; i < w; ++i) field[i].resize(h);
		
		for(int i = 0; i < n; ++i){
			cin >> c >> d >> x >> y;
			
			if(d == 0){
				for(int j = 0; j < 4; ++j){
					for(int k = 0; k < 2; ++k){
						field[x + j - 1][y + k - 1] = c;
					}
				}
			}else{
				for(int j = 0; j < 2; ++j){
					for(int k = 0; k < 4; ++k){
						field[x + j - 1][y + k - 1] = c;
					}
				}
			}
		}
		
		que.push(complex< int >(xs - 1, ys - 1));
		color = field[xs - 1][ys - 1];
		exist = false;
		
		while(!que.empty()){
			complex< int > pos = que.front();
			que.pop();
			
			if(pos.real() == xg - 1 && pos.imag() == yg - 1){
				exist = true;
				break;
			}
			
			if(pos.real() > 0 && field[pos.real() - 1][pos.imag()] == color) que.push(pos + complex< int >(-1, 0));
			if(pos.real() < w - 1 && field[pos.real() + 1][pos.imag()] == color) que.push(pos + complex< int >(1, 0));
			if(pos.imag() > 0 && field[pos.real()][pos.imag() - 1] == color) que.push(pos + complex< int >(0, -1));
			if(pos.imag() < h - 1 && field[pos.real()][pos.imag() + 1] == color) que.push(pos + complex< int >(0, 1));
			
			field[pos.real()][pos.imag()] = 0;
			
			
		}
		
		cout << (exist ? "OK" : "NG") << endl;
	}
	
	return 0;
}