#include<iostream>
using namespace std;


int board[100][100], h, w, xs, ys, xg, yg, n;
bool mem[100][100];
int col;


bool dfs(int x, int y)
{
  bool b = false;
  if(x == xg && y == yg)
    return true;
  if(mem[x][y])
    return false;

  mem[x][y] = true;
  b = false;
  if(x < w - 1 && board[x + 1][y] == col)
  {
    b |= dfs(x + 1, y);
  }
  if(!b && x > 0 && board[x - 1][y] == col)
  {
    b |= dfs(x - 1, y);
  }
  if(!b && y < h - 1 && board[x][y + 1] == col)
  {
    b |= dfs(x, y + 1);
  }
  if(!b && y > 0 && board[x][y - 1] == col)
  {
    b |= dfs(x, y - 1);
  }
  return b;
}


int main()
{
  while(true)
  {
    cin >> w >> h;
    if(!w)
      break;
    cin >> xs >> ys >> xg >> yg >> n;
    xs--; ys--; xg--; yg--;
    for(int i = 0; i < n; i++)
    {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      x--; y--;
      board[x][y] = d;
      if(d == 0)
        board[x][y + 1] = c; 
      else
        board[x + 1][y] = c;

    }
    col = board[xs][ys];
    if(dfs(xs, ys))
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
}