#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int sx,sy,gx,gy,col;
bool func(vector<vector<int> >out,vector<vector<bool> >&out2,int x,int y){
  out2[x][y]=true;
  loop(i,-1,2)loop(j,-1,2){
    if(out2[x+i][y+j]!=true&&out[x+i][y+j]==col)func(out,out2,x+i,y+j);
  }
}
int main(){
  int n,m;
  while(cin>>m>>n,n|m){
    cin>>sx>>sy>>gx>>gy;
    int nn;cin>>nn;
    vector<vector<int> >out(n+2);
    vector<vector<bool> >out2(n+2);
    rep(i,n+2)rep(j,m+2)out[i].pb(0);
    rep(i,n+2)rep(j,m+2)out2[i].pb(false);
    rep(q,nn){
      int a,b,c,d;
      cin>>a>>b>>d>>c;
      if(b)rep(i,4)rep(j,2)out[i+c][j+d]=a;
      else rep(i,2)rep(j,4)out[i+c][j+d]=a;
    }
    /*cout<<endl;
    rep(i,n){
      rep(j,m)cout<<" "<<out[i+1][j+1];
      cout<<endl;
      }*/
    
    if(out[gx][gy]==0||out[gx][gy]!=out[sx][sy]||out[sx][sy]==0){
      cout<<"NG"<<endl;
      continue;
    }
    col=out[sx][sy];
    func(out,out2,sx,sy);
    if(out2[gx][gy])cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
    /*rep(i,n){
      rep(j,m)cout<<" "<<out[i+1][j+1];
      cout<<endl;
      }*/
  }
}