#include <iostream>
#include <vector>

using namespace std;

int dxdy[4][2] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0}  };

bool doFill(vector<vector<char> >& brd, int i, int j, int w, int h, char c){
    if( i < 0 || j < 0 || i >= h || j >= w ) return false;
    if(brd[i][j] == 'G') return true;
    else if(brd[i][j] == c) brd[i][j] = '*';
    else return false;
    bool b = false;
    for(int k = 0; k < 4; ++k){
       b |= doFill(brd, i+dxdy[k][0], j+dxdy[k][1], w, h, c);
    }
    return b;
}

int main(){
    int w,h;
    int sx, sy;
    int gx, gy;
    int n;
    int i,j;
    cin >> w >> h;
    if(!w && !h) return 0;
    cin >> sx >> sy;
    cin >> gx >> gy;
    cin >> n;
    sx--; sy--; gx--; gy--;
    vector< vector<char> > board(h,vector<char>(w));
    for(i=0;i<h;++i)
        for(j=0;j<w;++j) board[i][j] = '.';
    while(n--){
        char c;
        int d, x, y;
        cin >> c >> d >> x >> y;
        x--; y--;
        for(i=0;i<2;++i){
            for(j=0;j<4;++j) {
                if(d == 1) 
                    board[y+j][x+i] = c;
                else
                    board[y+i][x+j] = c;
            }
        }
    }
    board[gy][gx] = 'G';
    if(doFill(board, sy, sx, w, h, board[sy][sx])){
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }/*
    for(i=0;i<h;++i) {
        for(j=0;j<w;++j) cout << board[i][j];
        cout << endl;
    }
    cout << endl;
    */return main();
}