#include <iostream>

using namespace std;

int w, h;

int field[100][100];
int pathToGoal[100][100];

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

int dfs(int x, int y, int goalX, int goalY, int color) {
    pathToGoal[y][x] = 1;
    if (x == goalX && y == goalY) {
        return 1;
    }
    int res = 0;
    for (int i = 0; i < 4; ++i) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (0 <= nx && nx < w && 0 <= ny && ny < h && pathToGoal[ny][nx] == -1 && field[ny][nx] == color) {
            res += dfs(nx, ny, goalX, goalY, color);
        }
    }
    return res;
}

int main() {
    while (true) {
        cin >> w >> h;
        if (w == 0 && h == 0) {
            return 0;
        }

        for (int i = 0; i < 100; ++i) {
            for (int j = 0; j < 100; ++j) {
                field[i][j] = -1;
                pathToGoal[i][j] = -1;
            }
        }

        int xs, ys;
        int xg, yg;
        int n;
        cin >> xs >> ys;
        cin >> xg >> yg;
        cin >> n;
        xs--;
        ys--;
        xg--;
        yg--;
        for (int i = 0; i < n; ++i) {
            int c, d, x, y;
            cin >> c >> d >> x >> y;
            x--;
            y--;
            if (d == 0) {
                for (int p = 0; p < 2; ++p) {
                    for (int q = 0; q < 4; ++q) {
                        field[y + p][x + q] = c;
                    }
                }
            }
            else {
                for (int p = 0; p < 4; ++p) {
                    for (int q = 0; q < 2; ++q) {
                        field[y + p][x + q] = c;
                    }
                }
            }
        }

        if (dfs(xs, ys, xg, yg, field[xs][ys]) > 0) {
            cout << "OK" << endl;
        }
        else {
            cout << "NG" << endl;
        }
    }
}