#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<vector>
#include<algorithm>
#include<string.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << x << endl;
using namespace std;

int xstart, ystart;
int xgoal, ygoal;
int load;
bool check;

void answer(int maze[][1000], int x, int y){
    if(load == maze[x][y]){
        maze[x][y] = 0;
    }else{
        return;
    }
    if(x == xgoal && y == ygoal){
        cout << "OK" << endl;
        check = true;
        return;
    }
    answer(maze, x+1,y);
    answer(maze, x,y+1);
    answer(maze, x,y-1);
    answer(maze, x-1,y);
}

int main(){
    int width, height;
    int n;
    int color, direction, x, y;

    while(cin >> width >> height, height){
        int maze[1000][1000];
        check = false;
        cin >> xstart >> ystart >> xgoal >> ygoal >> n;
        rep(i,n){
            cin >> color >> direction >> x >> y;
            if(direction == 0){
                maze[x][y] = color;
                maze[x+1][y] = color;
                maze[x+2][y] = color;
                maze[x+3][y] = color;
                maze[x][y+1] = color;
                maze[x+1][y+1] = color;
                maze[x+2][y+1] = color;
                maze[x+3][y+1] = color;
            }else{
                maze[x][y] = color;
                maze[x][y+1] = color;
                maze[x][y+2] = color;
                maze[x][y+3] = color;
                maze[x+1][y+1] = color;
                maze[x+1][y+2] = color;
                maze[x+1][y+3] = color;
                maze[x+1][y+4] = color;
            }
        }
        load = maze[xstart][ystart];
        answer(maze, xstart, ystart);
        if(check == false){
            cout << "NG" << endl;
        }
    }
}