#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int fie[102][102];
int check[102][102];
typedef struct state{
  int x;
  int y;
  int cost;
  state(int x,int y,int cost):x(x),y(y),cost(cost){}
};
int w,h;
int xg,yg;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
void makefie(int c,int d,int x,int y){
  int xm=0,ym=0;
  //cout << "oo";
  //fflush(stdout);
  if(d){ xm=2; ym=4;}
  else{ xm=4; ym=2;}
  for(int i=x; i < x+xm; i++){
    for(int j=y; j < y+ym; j++)
      fie[i][j]=c;
  }
  //  cout << "ee";
  // fflush(stdout);
}
int solve(int x,int y,int c){
  queue <state> q;
  q.push( state(x,y,0) );
  // cout << x << " " << y << " "<<endl;
  while(!q.empty()){
    state p = q.front(); q.pop();
    int cost = p.cost;
    for(int i=0;i<4;i++){
      int nx=p.x+dx[i];
      int ny=p.y+dy[i];
      if(nx <= 0 || nx >w || ny <= 0 || ny>h) continue;
      if(fie[nx][ny]!=c) continue;
      if(nx==xg && ny==yg) return 1;
      if(check[nx][ny]!=-1) continue;
      check[nx][ny]=cost+1;
      q.push( state(nx,ny,cost+1) );
      //  cout << nx << " " << ny << " "<< cost+1<<endl;
    }
  }
  return 0;
}
main(){
  int n;
  int xs,ys;
  while(1){
    cin >> w >>h;
    if(w==0 && h==0) break;
    cin >> xs >> ys;
    cin >> xg >> yg;
    cin >> n;
    memset(fie,0,sizeof(fie));
    memset(check,-1,sizeof(check));
    for(int i=0;i<n;i++){
      int c,d,x,y;
      cin >> c >> d >> x >> y;
      makefie(c,d,x,y);
    }

    if(fie[xs][ys]==0){ cout << "NG"<<endl; continue;}
    int res=solve(xs,ys,fie[xs][ys]);
    if(res) cout << "OK" <<endl;
    else cout << "NG" << endl;
  }
}