#include<iostream>
using namespace std;

int m[102][102];
int w, h, xs, ys, xg, yg, f, t;

void solve(int x, int y){
  if(x < 0 || y < 0 || x >= w || y >= h || f || m[x][y] == -1) return;
  if(x == xg && y == yg){
    f = 1;
    return;
  }
  m[x][y] = -1;
  if(m[x + 1][y] == t) solve(x + 1, y);
  if(m[x - 1][y] == t) solve(x - 1, y);
  if(m[x][y + 1] == t) solve(x, y + 1);
  if(m[x][y - 1] == t) solve(x, y - 1);
}

int main(void){
  int n, c, d, x, y;
  for( ; ; ){
    cin >> w >> h;
    if(!w && !h) break;

    for(int i = 0;i <= 101; i++)
      for(int j = 0;j <= 101; j++) m[i][j] = 0;

    cin >> xs >> ys >> xg >> yg >> n;
    xs--; ys--; xg--; yg--;

    for(int i = 0;i < n; i++){
      cin >> c >> d >> x >> y;
      x--; y--;
      if(!d){
        for(int i = 0;i < 4; i++) m[x + i][y] = m[x + i][y + 1] = c;
      } else {
        for(int i = 0;i < 4; i++) m[x][y + i] = m[x + 1][y + i] = c;
      }
    }

    f = 0;
    t = m[xs][ys];
    solve(xs, ys);

    cout << (f? "OK" : "NG") << endl;
  }
}
