#include<bits/stdc++.h>
using namespace std;

struct block{
  int x, y, c;
  bool var;//0テ」ツ?ョテヲツ卍?*4, 1テ」ツ?ョテヲツ卍?*2
  block(int c_, bool var_, int x_, int y_):
    c(c_), var(var_), x(x_), y(y_){
  };
  int GetWidth(){
    if(var)return 2;
    else return 4;
  }
  int GetHight(){
    if(var)return 4;
    else return 2;
  }
};

void paint(vector<string>& grid, block b){
  for (int i = b.y; i < b.y + b.GetHight(); i++) {
    for (int j = b.x; j < b.x + b.GetWidth(); j++) {
      grid[i][j] = b.c + '0';
    }
  }
}
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int w, h;

bool range(int x, int y){
  return (0 <= x && x < w && 0 <= y && y < h);
}

bool dfs(vector<string>& grid, vector<vector<bool> > &visited,
         int x, int y, int gx, int gy, char c){
  if(x == gx && y == gy)return true;
  bool res = false;
  for (int i = 0; i < 4; i++) {
    if(!range(x + dx[i], y + dy[i]))continue;
    if(visited[y + dy[i]][x + dx[i]] == true)continue;
    if(grid[y + dy[i]][x + dx[i]] != c)continue;
    visited[y + dy[i]][x + dx[i]] = true;
    res |= dfs(grid, visited, x + dx[i], y + dy[i], gx, gy, c);
  }
  return res;
}

int main(int argc, char *argv[]){
  while(std::cin >> w >> h, w){
    int sx, sy, gx, gy, n;
    std::cin >> sx >> sy >> gx >> gy >> n;
    sx--;sy--;gx--;gy--;
    vector<string> grid(h, string(w, '.'));
    vector<block> b;
    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      std::cin >> c >> d >> x >> y;
      x--;y--;
      b.push_back(block(c, d, x, y));
      paint(grid, b[i]);
    }
    // for (int i = 0; i < grid.size(); i++) {
    //   std::cout << grid[i] << std::endl;
    // }
    vector<vector<bool> > visited(h, vector<bool>(w, false));
    visited[sy][sx] = true;;
    if(dfs(grid, visited, sx, sy, gx, gy, grid[sy][sx])){
      std::cout << "OK" << std::endl;
    }else{
      std::cout << "NG"<< std::endl;
    }

  }
  return 0;
}