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

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

void dfs(int y, int x, vector<vector<int>>& v) {
    int c = v[y][x];
    v[y][x] = -1;
    for(int i=0; i<4; ++i) {
        int ny = y + dy[i], nx = x + dx[i];
        if(ny < 0 || v.size() <= ny || nx < 0 || v[0].size() <= nx || v[ny][nx] != c) {
            continue;
        }
        dfs(ny, nx, v);
    }
}

int main() {
    int w, h;
    while(cin >> w >> h, w) {
        int xs, ys, xg, yg;
        cin >> xs >> ys >> xg >> yg;
        xs--; ys--; xg--; yg--;

        vector<vector<int>> v(h, vector<int>(w));
        int n;
        cin >> n;
        for(int i=0; i<n; ++i) {
            int c, d, x, y;
            cin >> c >> d >> x >> y;
            x--; y--;
            int size[2] = {2, 4};
            for(int j=y; j<y+size[d]; ++j) {
                for(int k=x; k<x+size[(d+1)%2]; ++k) {
                    v[j][k] = c;
                }
            }
        }
        dfs(ys, xs, v);
        if(v[yg][xg] == -1) {
            cout << "OK" << endl;
        } else {
            cout << "NG" << endl;
        }
    }
}
