#include <bits/stdc++.h>
using namespace std;
const int limit = 100;
int w, h, n;
int xs, ys, xg, yg;
int maze[limit][limit];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int flag = 0;

void dfs(int y, int x){
    maze[y][x] = 0;
    //4近傍を探索
    for(int i=0; i < 4; i++){
            int nx = x + dx[i], ny = y + dy[i];
            if(0 <= nx and nx < h and 0 <= ny and ny < w and maze[ny][nx] != 0){
                if(nx == (xg-1) and ny == (yg-1)) { flag = 1; return; }
                dfs(ny, nx);
            }
        }
    return;
}


int main(){
    while(1){
    flag = 0;
    cin >> w >> h;
    if(w == 0 and h == 0) break;
    cin >> xs >> ys >> xg >> yg >> n;
    //ボードを初期化
    for(int i=0; i < w; i++)for(int j=0; j < h; j++) maze[i][j] = 0;
    //ボードにブロックを敷き詰める
    for(int i=0; i < n; i++){
        int c = 0, d = 0, x = 0, y = 0;
        cin >> c >> d >> x >> y;
        if(d)for(int dx=0; dx < 2; dx++)for(int dy=0; dy < 4; dy++) maze[y-1+dy][x-1+dx] = c;
        else for(int dy=0; dy < 2; dy++)for(int dx=0; dx < 4; dx++) maze[y-1+dy][x-1+dx] = c;
    }
    //迷路を単純化する
    for(int i=0; i < w; i++)for(int j=0; j < h; j++) if(maze[i][j] != maze[ys-1][xs-1]) maze[i][j] = 0;
    //debugの為に出力
    /*
    for(int i=0; i < w; i++){
        for(int j=0; j < h; j++) cout << maze[i][j];
        cout << endl;
    }
    */
    //search
    dfs(ys-1, xs-1);
    if(flag) cout << "OK" << endl;
    else cout << "NG" << endl;
    }
    return 0;
}

