#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 x[4]={-1,1,0,0};
int y[4]={0,0,-1,1};
int color;
void func(vector<vector<int> >&in,vector<vector<int> >&map,int a,int b){
  //cout<<a<<" "<<b<<endl;
  map[a][b]=2;
  rep(i,4)if(in[a+x[i]][b+y[i]]==color&&map[a+x[i]][b+y[i]]==1)func(in,map,a+x[i],b+y[i]);
}
int main(){
  int n,m;
  while(cin>>m>>n,n||m){
    vector<vector<int> >in(n+2,vector<int>(m+2));
    int xs,ys,xg,yg;
    cin>>ys>>xs>>yg>>xg;
    int q;
    cin>>q;
    rep(i,q){
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      if(b)rep(i,2)rep(j,4)in[i+c][j+d]=a;
      else rep(i,4)rep(j,2)in[i+c][j+d]=a;
    }
    //cout<<n<<" "<<m<<endl;
    //loop(i,1,n+1){loop(j,1,m+1)cout<<" "<<in[i][j];cout<<endl;}

    if(in[xs][ys]==0||in[xg][yg]==0){cout<<"NG"<<endl;continue;}
    color=in[xs][ys];
    vector<vector<int> >map(n+2,vector<int>(m+2));
    loop(i,1,n+1)loop(j,1,m+1)map[i][j]=1;
    //loop(i,1,n+1){loop(j,1,m+1)cout<<" "<<map[i][j];cout<<endl;}

    func(in,map,xs,ys);
    if(map[xg][yg]==2)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
    //cout<<n<<" "<<m<<endl;
    //loop(i,1,n+1){loop(j,1,m+1)cout<<" "<<map[i][j];cout<<endl;}
  }
}