#include <iostream>
using namespace std;
 
int weight, hight;
int g[101][101] = {0};
int sc;
int sx, sy, gx, gy;
bool flag = false;
const int vx[4] = {0, 0, 1, -1};
const int vy[4] = {1, -1, 0, 0};
 
void dfs(int x, int y){
    if(x == gx && y == gy){
        flag = true;
        return;
    }
    
    if(g[y][x] == 0){
        flag = false;
        return;
    }
    
    g[y][x] = -1;
    
    for(int i = 0;i < 4;i++){
        int nx = x + vx[i];
        int ny = y + vy[i];
         
        if(nx >= 0 && nx < weight && ny >= 0 && ny < hight && g[ny][nx] == sc){
            dfs(nx, ny);
        }
    }
    return;
}
 
int main(){
    while(1){
        int n, c, d, x, y;
        flag = false;
        g[101][101] = {0};
        
        cin >> weight >> hight;
        
        if(weight == 0 && hight == 0){
            break;
        }
         
        cin >> sx >> sy >> gx >> gy >> n;
        sx--; sy--; gx--; gy--;
         
        for(int i = 0;i < n;i++){
            cin >> c >> d >> x >> y;
            x--; y--;
             
            if(d == 0){
                for(int h = 0;h < 2;h++){
                    for(int w = 0;w < 4;w++){
                        g[y+h][x+w] = c;
                    }
                }
            }else{
                for(int h = 0;h < 4;h++){
                    for(int w = 0;w < 2;w++){
                        g[y+h][x+w] = c;
                    }
                }
            }
        }
         
        sc = g[sy][sx];
        dfs(sx, sy);
         
        if(flag){
            cout << "OK" << endl;
        }else{
            cout << "NG" << endl;
        }
    }
     
    return 0;
}