#include <iostream>
using namespace std;

int f[102][102];

void draw(int c,int d,int x,int y){
    if(d){
        for(int i=x;i<x+2;i++){
            for(int j=y;j<y+4;y++){
                f[i][j]=c;
            }
        }
    }
}



bool DFS(int xs,int ys,int xg,int yg){
    while(xs!=xg||ys!=yg){
        if(DFS(xs+1,ys,xg,yg))
          xs++;
        else if(DFS(xs-1,ys,xg,yg))
          xs--;
        else if(DFS(xs,ys+1,xg,yg))
          ys++;
        else if(DFS(xs,ys-1,xg,yg))
          ys--;
        else{
            return false;
        }
    }
    return true;
}

int main(){
    int w,h;
    int xs,ys;
    int xg,yg;
    int n;
    int c;
    int d,x,y;
    while(1){
        cin>>w>>h;
        cin>>xs>>ys;
        cin>>xg>>yg;
        cin>>n;

        for(int i=0;i<n;i++){
            cin>>c>>d>>x>>y;
            draw(c,d,x,y);
        }
        if(DFS(xs,ys,xg,yg)){
            cout<<"OK"<<endl;
        }else{
            cout<<"NG"<<endl;
        }
    }
    return 0;
}
