#include <iostream>
#include <vector>

using namespace std;

const int dx[] = {0, -1, 0, 1};
const int dy[] = {-1, 0, 1, 0};

bool fill(vector<vector<int> > &v, int x, int y, int gx, int gy) {
    if(x == gx && y == gy) return true;

    int W = v.size();
    int H = v[0].size();
    int clr = v[x][y];
    v[x][y] = 0;

    for(int i = 0; i < 4; ++i) {
        int xx = x + dx[i];
        int yy = y + dy[i];

        if(0 <= xx && xx < W && 0 <= yy && yy < H) {
            if(v[xx][yy] == clr) {
                if(fill(v, xx, yy, gx, gy)) return true;
            }
        }
    }
    return false;
}

int main() {
    while(true) {
        int W, H;
        int sx, sy, gx, gy;
        int N;

        cin >> W >> H;
        if(!W && !H) break;
        cin >> sx >> sy >> gx >> gy >> N;
        --sx; --sy; --gx; --gy;

        vector<vector<int> > v(W, vector<int>(H, 0));
        for(int i = 0; i < N; ++i) {
            int c, d, x, y;
            cin >> c >> d >> x >> y;
            --x; --y;
            int w = d ? 2 : 4;
            int h = d ? 4 : 2;
            for(int dx = 0; dx < w; ++dx) 
                for(int dy = 0; dy < h; ++dy)
                    v[x+dx][y+dy] = c;
        }

        if(v[sx][sy] != 0 && fill(v, sx, sy, gx, gy)) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
    return 0;
}
#include <cstdio>
#include <functional>
#include <vector>
#include <algorithm>

int testcase_ends() {
  int w, h;
  scanf("%d %d", &w, &h);
  if (w == 0 && h == 0)
    return 1;

  int xs, ys;
  scanf("%d %d", &xs, &ys);

  int xg, yg;
  scanf("%d %d", &xg, &yg);

  std::vector<std::vector<int>> g(h+2, std::vector<int>(w+2));

  int n;
  scanf("%d", &n);

  for (int i=0; i<n; ++i) {
    int c, d, x, y;
    scanf("%d %d %d %d", &c, &d, &x, &y);

    int dh=2, dw=2;
    (d? dh:dw) += 2;

    for (int j=0; j<dh; ++j)
      for (int k=0; k<dw; ++k)
	g[y+j][x+k] = c;
  }

  // for (int i=0; i<h; ++i)
  //   for (int j=0; j<w; ++j)
  //     fprintf(stderr, "%d%c", g[i][j], j+1<w? ' ':'\n');

  if (g[ys][xs] != g[yg][xg])
    return !printf("NG\n");

  const int dy[]={-1, 0, 1, 0};
  const int dx[]={0, -1, 0, 1};
  std::function<bool (int, int)> dfs=[&](int x, int y) {
    if (x == xg && y == yg) return true;

    int cs=g[y][x];
    g[y][x] = -cs;  // mark visited
    for (int k=0; k<4; ++k) {
      int cd=g[y+dy[k]][x+dx[k]];
      if (cs == cd && dfs(x+dx[k], y+dy[k]))
	return true;
    }
    return false;
  };

  printf("%s\n", dfs(xs, ys)? "OK":"NG");
  return 0;
}      

int main() {
  while (!testcase_ends()) {}
}

