#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
#include<queue>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
struct point{
    int x,y;
    point(){}
    point(int a, int b){x = a;y = b;}
};
int main(void){

    int w,h;
    while(cin>>w>>h,w){
        int xs,ys,xg,yg,n;
        cin>>xs>>ys>>xg>>yg>>n;
        int field[120][120] = {{0}};
        for(int i = 0;i < n;i++){
            int c,d,x,y;
            int dw = 4,dh = 2;
            cin>>c>>d>>x>>y;
            if(d)swap(dw,dh);
            for(int di = y;di < dh + y; di++){
                for(int dj = x;dj < dw + x;dj++){
                    field[di][dj] = c;
                }
            }
        }
        int C = field[xs][ys];
        bool vis[120][120] = {{false}};
        queue<point> Q;
        Q.push(point(xs,ys));
        if(field[xg][yg] != C || C == 0)cout<<"NG"<<endl;
        else {
            while(!Q.empty()){
                point P = Q.front();
                Q.pop();
                for(int i = 0;i < 4;i++){
                    point p = point(P.x + dx[i],P.y + dy[i]);
                    if(1 <= p.x && p.x <= w && 1 <= p.y && p.y <= h){
                        if(!vis[p.x][p.y]&&field[p.x][p.y] == C){

                            vis[p.x][p.y] = true;
                            Q.push(p);
                        }
                    }
                }
            }

        if(vis[xg][yg])cout<<"OK"<<endl;
        else cout<<"NG"<<endl;
        }
/*
        for(int i = 0;i < h;i++){
            for(int j = 0;j < w;j++){
                cout<<field[i][j]<<" ";
            }
            cout<<endl;
        }
        cout<<endl<<endl;
        for(int i = 0;i < h;i++){
            for(int j = 0;j < w;j++){
                cout<<vis[i][j]<<" ";
            }
            cout<<endl;
        }*/
        //cout<<C<<"---"<<field[xg][yg]<<endl;
    }


    return 0;
}