#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define INF 1010001000
#define loop(i, n) for (int i = 0; i < n; i++)
#define mp make_pair
typedef pair<int, int> i_i;

bool dfs(vector<vector<int> > &g);

int sx, sy, gx, gy;
int n, m; 
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int main()
{

while(cin >> n >> m,(n|m)){
 m++; n++;
 vector<vector<int> > graph(m,vector<int>(n,0));
 
 cin>>sx>>sy>>gx>>gy;
 int bl;  cin>>bl;
 loop(i, bl){
  int a,b,c,t; cin>>a>>b>>c>>t;
  if(b){
   for(int j=t;j<t+2;j++){
    for(int k=c;k<c+4;k++){
     graph[k][j] = a;
    }
   } 
  } else {
   for(int j=c;j<c+2;j++){
    for(int k=t;k<t+4;k++){
     graph[k][j] = a;
    }
   }
  }
 }
cout << (dfs(graph)) ? "OK" : "NG" << endl;
}
return 0;
}

bool dfs(vector<vector<int> > &g) {
int cl = g[sx][sy];
vector<vector<bool> > vsed(m,vector<bool>(n,false));
queue<i_i > q;
q.push(mp(sx,sy));
while(!q.empty()){
int x = q.top().first, y = q.top().second;
q.pop();
if(x == gx && y == gy){
return true;
}
if(vsed[x][y]){
continue;
} else {
vsed[x][y]=true;
}

loop(i, 4) {
int nx = x +dx[i], ny = y +dy[i];
if(0<nx && nx < n && 0<ny && ny < m){
if(g[nx][ny] == cl){
q.push(mp(nx,ny));
}
} 
}

}
return false;
}