// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

int di[] = {1, 0, -1, 0}, dj[] = {0, 1, 0, -1};

void solve() {
  int w, h;
  while (cin >> w >> h, w) {
    int sx, sy, gx, gy, n;
    cin >> sx >> sy >> gx >> gy >> n;
    sx--, sy--, gx--, gy--;
    vvi v(h, vi(w));
    rep(i, n) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      x--;
      y--;
      rep(i, 2 + d * 2) rep(j, 4 - d * 2) v[y + i][x + j] = c;
    }
    int roadColor = v[sy][sx];
    function<bool(int, int)> dfs = [&](int i, int j) {
      if (i < 0 || j < 0 || i >= h || j >= w || v[i][j] != roadColor) return false;
      if (i == gy && j == gx) return true;
      v[i][j] = -1;
      bool b  = false;
      rep(k, 4) b |= dfs(i + di[k], j + dj[k]);
      return b;
    };
    cout << (dfs(sy, sx) ? "OK" : "NG") << endl;
  }
}