#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

struct state {
	int x, y;
	state(int x, int y) : x(x), y(y) {};
};

int main() {
	int w, h;
	while(cin >> w >> h, w) {
		vvi field(h+1, vi(w+1));
		vvi visit(h+1, vi(w+1));
		
		int xs, ys, xg, yg, n;
		cin >> xs >> ys >> xg >> yg >> n;

		int c, d, x, y;
		REP(i, n) {
			cin >> c >> d >> x >> y;
			REP(j, 4) {
				REP(k, 2) {
					if(d) {
						field[y+j][x+k] = c;
					} else {
						field[y+k][x+j] = c;
					}
				}
			}
		}

		stack<state> S;
		S.push(state(xs, ys));
		int color = field[ys][xs];
		bool goal = false;
		while(!S.empty()) {
			state st = S.top();
			S.pop();

			if(st.x == xg && st.y == yg) {
				goal = true;
				break;
			}

			int nx, ny;
			REP(d, 4) {
				nx = st.x + dx[d];
				ny = st.y + dy[d];
				if(0<=nx && nx<w && 0<=ny && ny<h) {
					if(!visit[ny][nx] && field[ny][nx] == color) {
						visit[ny][nx] = 1;
						S.push(state(nx, ny));
					}
				}

			}
		}

		if(goal) {
			cout << "OK" << endl;
		} else {
			cout << "NG" << endl;
		}
	}
}