#include <iostream>
#include <vector>
using namespace std;

int needleX[4] = {-1, 0, 1, 0};
int needleY[4] = {0, 1, 0, -1};

bool dfs(int x, int y, int goalx, int goaly,vector<vector<int> >& canGo){

    //??´??????????????????????????????true
    if(x == goalx && y == goaly){ return true; }

    //???????????°????????¢?´¢???????????????
    canGo[x][y] = false;

    //???????????????????????¢?´¢
    for(int i = 0; i < 4; i++){
        int nextx = x + needleX[i];
        int nexty = y + needleY[i];

        //?????????????????????
        if(canGo[nextx][nexty]){
            bool flag = dfs(nextx, nexty, goalx, goaly, canGo);
            if(flag){
                return true;
            }
        }
    }

    return false;
}


int block(int w, int h){

    //0 0??§??????
    if(w == 0 && h == 0){return 0;}

    //??????????????±??\???
    int xs, ys, xg, yg;
    int n;
    int c, d, inputX, inputY;
    vector<vector<int> > canGo(h + 2, vector<int>(w + 2, 0));
    cin >> xs >> ys;
    cin >> xg >> yg;
    cin >> n;

    //??????????????????
    for(int i = 1; i <= n; i++){
        cin >> c >> d >> inputX >> inputY;
        if(d == 0){
            for(int j = 0; j < 4; j++){
                for(int k = 0; k < 2; k++){
                    canGo[inputY + k][inputX + j] = c;
                }
            }
        }else{
            for(int j = 0; j < 2; j++){
                for(int k = 0; k < 4; k++){
                    canGo[inputY + k][inputX + j] = c;
                }
            }
        }   
    }
    /*??????????????¨???
    cout << canGo[ys][xs] << endl;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cout << canGo[i][j];
        }
        cout << endl;
    }
    cout << endl;
    */

    //????????????bool????????¨?????????
    int load = canGo[ys][xs];
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(canGo[i][j] == load){
                canGo[i][j] = 1;
            }else{
                canGo[i][j] = 0;
            }
        }
    }
    
    // ??±???????????¢?´¢????????????????????????
    bool result = dfs(xs,ys,xg,yg,canGo);
    if(result){
        return 1;
    }else{
        return 2;
    }

    
}

int main(void){
    int i = 0;
    int array[30];
    int w, h;
    while(1){
        cin >> w >> h;
        array[i] = block(w, h);
        if(array[i] == 0){break;}
        i++;
    }
    for(int j = 0; j < i; j++){
        if(array[j] == 1){cout << "OK" << endl;}
        else {cout << "NG" << endl;}
    }

    return 0;
}