#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <cassert>
#include <utility>

using namespace std;

typedef pair<int, int> P;

#define mp(a,b) make_pair(a,b)
#define DEBUG(x) cerr<<#x<<":"<<x<<endl;

int W, H;
int SX, SY, GX, GY;

int field[100][100];

inline bool inRange(int x, int y) {
	return 0 <= x && x < W && 0 <= y && y < H;
}

void setBlock(int c, int d, int x, int y) {
	if(d == 0) {
		for(int dy = 0; dy < 2; dy++) {
			for(int dx = 0; dx < 4; dx++) {
				field[x + dx][y + dy] = c;
			}
		}
	}
	else if(d == 1) {
		for(int dy = 0; dy < 4; dy++) {
			for(int dx = 0; dx < 2; dx++) {
				field[x + dx][y + dy] = c;
			}
		}
	}
	else
		assert(false);
}

void pv() {
	cerr << endl;
	cerr << "-----" << endl;
	for(int y = 0; y < H; y++) {
		for(int x = 0; x < H; x++)
			cerr << field[x][y];
		cerr << endl;
	}
	cerr << "-----" << endl;
}

bool visit[100][100];

int main() {
	for(; cin >> W >> H;) {
		cin >> SX >> SY >> GX >> GY;
		SX--, SY--, GX--, GY--;

		memset(field, 0, sizeof field);
		memset(visit, 0, sizeof visit);
		
		int N; cin >> N;
		for(int i = 0; i < N; i++) {
			int c, d, x, y;
			cin >> c >> d >> x >> y;
			x--, y--;
			setBlock(c, d, x, y);
		}

		queue<P> Q;
		Q.push(mp(SX, SY));
		visit[SX][SY] = true;

		int C = field[SX][SY];

		bool f = false;
		while(!Q.empty()) {
			P p = Q.front(); Q.pop();
			if(p.first == GX && p.second == GY) {
				f = true;
				break;
			}
			for(int i = 0; i < 4; i++) {
				int dx[4] = {1, 0, -1, 0};
				int dy[4] = {0, 1, 0, -1};
				int nx = p.first + dx[i];
				int ny = p.second + dy[i];
				if(inRange(nx, ny) && field[nx][ny] == C && visit[nx][ny] == false) {
					visit[nx][ny] = true;
					Q.push(mp(nx, ny));
				}
			}
		}

		cout << (f ? "OK" : "NG") << endl;
	}
}