#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

bool isMaze;
int blocks[105][105], xg, yg, w,h;

void dfs(int target, int x, int y){
    if(x < 0 || y < 0 || x >= w || y >= h) return;
    if(x == xg && y == yg){
        isMaze = true;
        return;
    }
    if(blocks[y][x] != target || blocks[y][x] == 0){
        return;
    }

    blocks[y][x] = 9;
    
    dfs(target, x + 1, y);
    dfs(target, x - 1, y);
    dfs(target, x, y + 1);
    dfs(target, x, y - 1);
    return;
}

int main(){
    int xs, ys, n;
    while(cin >> w >> h, w||h){
        rep(i,h) rep(j,w) blocks[i][j] = 0;
        cin >> xs >> ys >> xg >> yg >> n;
        xs--; ys--; xg--; yg--;
        rep(i,n){
            int c, d, x, y;
            cin >> c >> d >> x >> y;
            x--; y--;
            rep(j, (d?4:2)) rep(k, (d?2:4)) b[x + j][y + k] = c;
        }
        isMaze = false;
        dfs(blocks[ys][xs], xs, ys);

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