#include <vector>
#include <iostream>

enum class Color {
	goal, white, yellow, green, blue, red, null
};
void recursive(std::vector<std::vector<Color>> &vector, const int &x, const int &y, const Color c) {
	if (0 <= x && x < vector.at(0).size() && 0 <= y && y < vector.size() && vector.at(y).at(x) == c) {
		vector.at(y).at(x) = Color::goal;
		recursive(vector, x, y - 1, c); recursive(vector, x + 1, y, c); recursive(vector, x, y + 1, c); recursive(vector, x - 1, y, c);
	}
}
void fill(std::vector<std::vector<Color>> &vector, const int &x, const int &y, const Color &c) {
	for (auto i = 0; i < 2; ++i) {
		for (auto j = 0; j < 2; ++j) {
			vector.at(y + i).at(x + j) = c;
		}
	}
}
int main() {
	int w, h;
	std::cin >> w >> h;
	while (w != 0) {
		std::vector<std::vector<Color>> vector(h, std::vector<Color>(w, Color::null));
		int start_x, start_y;
		std::cin >> start_x >> start_y;
		int goal_x, goal_y;
		std::cin >> goal_x >> goal_y;
		int n;
		std::cin >> n;
		for (auto i = 0; i < n; ++i) {
			int c, d, x, y;
			std::cin >> c >> d >> x >> y;
			fill(vector, x - 1, y - 1, Color(c));
			fill(vector, x + 1 - 2 * d, y - 1 + 2 * d, Color(c));
		}
		recursive(vector, start_x - 1, start_y - 1, vector.at(start_y).at(start_x));
		if (vector.at(goal_y - 1).at(goal_x - 1) == Color::goal) {
			std::cout << "OK\n";
		}
		else {
			std::cout << "NG\n";
		}
		std::cin >> w >> h;
	}
	return 0;
}