#include <iostream>
using namespace std;
struct cordinate{
        int y;
        int x;
};
cordinate SIZE,Start,Goal;
struct Blocks{
        int color;
        int direction;
        int y;
        int x;
};
Blocks block[200];
int N,board[200][200];
int Color,dp[200][200];
int recursion(int y,int x){
        int res=0;
        if(board[y][x]==0)
                return false;
        if(y==Goal.y && x==Goal.x){
                return true;
        }
        else{
                board[y][x]=0;
                if(recursion(y+1,x))return true;
                if(recursion(y-1,x))return true;
                if(recursion(y,x+1))return true;
                if(recursion(y,x-1))return true;
        }
        return false;
}
int main(){
        while(true){
                for(int i=0 ; i<100 ; i++ )
                        for(int j=0 ; j<100 ; j++ ){
                                dp[i][j]=-1;
                                board[i][j]=0;
                        }
                cin >> SIZE.x >> SIZE.y;
                if(SIZE.x+SIZE.y==0)
                        break;
                cin >> Start.x >> Start.y;
                cin >> Goal.x >> Goal.y;
                cin >> N;
                for(int i=0 ; i<N ; i++ ){
                        cin >> block[i].color >> block[i].direction;
                        cin >> block[i].x >> block[i].y;
                        if(block[i].direction){
                                for(int l=block[i].y ; l<block[i].y+4 ; l++ ){
                                        for(int j=block[i].x ; j<block[i].x+2 ; j++ ){
                                                board[l][j]=block[i].color;
                                        }
                                }
                        }
                        else{
                                for(int l=block[i].y ; l<block[i].y+2 ; l++ ){
                                        for(int j=block[i].x ; j<block[i].x+4 ; j++ ){
                                                board[l][j]=block[i].color;
                                        }
                                }
                        }
                }
                Color=board[Start.y][Start.x];
                if(recursion(Start.y,Start.x)>0)
                        cout <<"OK"<<endl;
                else
                        cout <<"NG"<<endl;
        }
        return 0;
}