#include<bits/stdc++.h>
using namespace std;
int vx[4]={1,0,-1,0};int vy[4]={0,1,0,-1};int flag=0;int board[102][102]={0};vector<pair<int,int> > com;
queue<pair<pair<int,int>,int > > qp;int num=0;
pair<pair<int,int>,int > now;
int check(int i){
  if(now.second!=board[now.first.second+vy[i]][now.first.first+vx[i]])
    return 0;
  for(int j=0;j<com.size();j++)
    if(now.first.second+vy[i]==com[j].second&&now.first.first+vx[i]==com[j].first)
      return 0;
  return 1;
}
int main(){
  int w,h;
  while(cin>>w>>h,w+h!=0){
    flag=0;num=0;
    com.clear();
    while(!qp.empty())
      qp.pop();
    int xs,ys,xg,yg;
    for(int i=0;i<h+2;i++)
      for(int j=0;j<w+2;j++)
	board[i][j]=0;
    cin>>xs>>ys;cin>>xg>>yg;
    int n,c,d,x,y;
    cin>>n;
    for(int i=0;i<n;i++){
      cin>>c>>d>>x>>y;
      for(int j=0;j<2;j++){
	for(int k=0;k<4;k++){
	  if(d==0)
	    board[y+j][x+k]=c;
	  else
	    board[y+k][x+j]=c;
	}
      }
    }
    qp.push(make_pair(make_pair(xs,ys),board[ys][xs]));
    while(!qp.empty()){
      now=qp.front();
      qp.pop();
      for(int i=0;i<4;i++){
	num++;
	if(check(i)==1){
	  qp.push(make_pair(make_pair(now.first.first+vx[i],now.first.second+vy[i]),now.second));
	  com.push_back(make_pair(now.first.first+vx[i],now.first.second+vy[i]));
	  if(now.first.first+vx[i]==xg&&now.first.second+vy[i]==yg){
	    flag=1;
	    break;
	  }
	}
      }
      if(flag==1){cout<<"OK"<<endl;break;}
      if(num==10000){cout<<"NG"<<endl;break;}
    }
  }
  return 0;
}