#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
typedef pair<int, int> P;

const int INF = (int)1e9;

int board[128][128];

int main()
{
    int w, h;

    while (scanf("%d %d", &w, &h), w){
        int xs, ys;
        int xg, yg;
        scanf("%d %d", &xs, &ys);
        scanf("%d %d", &xg, &yg);

        int n;
        scanf("%d", &n);
        memset(board, 0, 128 * 128);
        while (n-- > 0){
            int c, d, x, y;
            scanf("%d %d %d %d", &c, &d, &x, &y);

            board[y][x] = board[y][x + 1] = c;
            board[y + 1][x] = board[y + 1][x + 1] = c;
            if (d == 0){
                board[y][x + 2] = board[y][x + 3] = c;
                board[y + 1][x + 2] = board[y + 1][x + 3] = c;
            }
            else {
                board[y + 2][x] = board[y + 3][x] = c;
                board[y + 2][x + 1] = board[y + 3][x + 1] = c;
            }
        }

        queue<P> que;
        bool flag = false;
        int color = board[ys][xs];

        if (!color){
            puts("NG");
            continue;
        }

        for (que.push(P(xs, ys)); que.size(); que.pop()){
            P p = que.front();
            int x = p.first;
            int y = p.second;

            if (board[y][x] != color) continue;

            if (x == xg && y == yg){
                flag = true;
                break;
            }
            board[y][x] = !color;
            que.push(P(x + 1, y));
            que.push(P(x - 1, y));
            que.push(P(x, y + 1));
            que.push(P(x, y - 1));
        }

        puts(flag ? "OK" : "NG");
    }

    return 0;
}
#include<iostream>
#include<string>
#include<queue>
using namespace std;

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

int board[100][100];

void init_board() {
    int i, j;
    for (i=0; i<100; i++) {
        for (j=0; j<100; j++) {
            board[i][j] = 0;
        }
    }
}
void put_block(int c, int d, int x, int y) {
    int i, j;
    int i_stop = d? 2+x: 4+x;
    int j_stop = d? 4+y: 2+y;
    for (i=x; i<i_stop; i++) {
        for (j=y; j<j_stop; j++) {
            board[i][j] = c;
        }
    }
}

string trace(int xs, int ys, int xg, int yg) {
    int x, y, nx, ny, i, c;
    queue<pair<int, int> > q;
    q.push(make_pair(xs, ys));
    c = board[xs][ys];
    if (c == 0) {
        return "NG";
    }
    board[xs][ys] = 0;
    while (q.size() > 0) {
        x = q.front().first;
        y = q.front().second;
        q.pop();
        if (x==xg && y==yg) {
            return "OK";
        }
        for (i=0; i<4; i++) {
            nx = x+dx[i];
            ny = y+dy[i];
            if (nx<0 || ny<0 || nx>=100 || ny>=100) {
                continue;
            }
            if (board[nx][ny] == c) {
                q.push(make_pair(nx, ny));
                board[nx][ny] = 0;
            }
        }
    }
    return "NG";
}

int main() {
    int w, h, xs, ys, xg, yg, n, c, d, x, y, i;
    while (true) {
        cin >> w >> h;
        if (w==0 && h==0) {
            break;
        }
        cin >> xs >> ys;
        cin >> xg >> yg;
        cin >> n;
        init_board();
        for (i=0; i<n; i++) {
            cin >> c >> d >> x >> y;
            put_block(c, d, x, y);
        }
        cout << trace(xs, ys, xg, yg) << endl;
    }

    return 0;
}