Relative B came to Mr. A's house. He is 3 years old and loves blocks. The block he has is shaped like Figure 1.

<image>

Figure 1

Mr. B is laying blocks on the board. When I asked him, "What are you making?", He replied cheerfully, "Maze !!". The maze he says is the arrangement of blocks that are in contact with each other from the start to the goal and can be traced only by blocks of the same color. Figure 2 shows that the yellow block creates a maze from the upper left (start) to the lower right (goal).

<image>

Figure 2

With Mr. B playing innocently, you, the programmer, decided to see if the blocks were arranged in a maze.

Create a program that inputs the block information, start, and goal coordinates, and outputs OK if the block is a maze, and NG if it is not. The board has the size of w in the horizontal direction and h in the vertical direction, and the upper left coordinate is (1, 1) and the lower right coordinate is (w, h). The blocks are 2x4 rectangles, all the same size. The block color c can be 1 (white), 2 (yellow), 3 (green), 4 (blue), or 5 (red). The orientation d of the block on the board is 0 if it is long horizontally and 1 if it is long vertically. The position of the block is represented by the coordinates (x, y) at the top left of the block. The position of the block does not overlap with other blocks and does not protrude from the board.



Input

A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:


w h
xs ys ys
xg yg
n
c1 d1 x1 y1
c2 d2 x2 y2
::
cn dn xn yn


The board size w, h (4 ≤ w, h ≤ 100) is given on the first line. The second line gives the start coordinates xs, ys, and the third line gives the goal coordinates xg, yg.

The number of blocks n is given on the 4th line. The next n lines are given the color ci, orientation di, position xi, yi of the i-th block.

The number of datasets does not exceed 30.

Output

The discrimination result is output to one line for each input data set.

Example

Input

20 20
1 1
9 9
7
2 0 1 1
5 1 1 3
2 1 3 3
1 1 5 2
5 1 7 3
2 0 2 7
2 0 6 8
20 20
9 9
1 1
6
2 0 1 1
1 0 5 1
2 1 1 3
5 0 1 7
3 1 5 5
4 1 8 5
0 0


Output

OK
NG
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int w,h;
int sx,sy;
int gx,gy;
int n;

vector<vector<int>> field;
int de[] = {1, 0, -1, 0};

void dfs(int x ,int y, int c) {
  if(x < 1 || x > w || y < 1 || y > h || field[x][y] != c) return;
  field[x][y] = -1;
  dfs(x + 1, y, c);
  dfs(x - 1, y, c);
  dfs(x, y + 1, c);
  dfs(x, y - 1, c);
}

int main() {
  while(cin >> w >> h, w && h) {
    field.assign(101, vector<int>(101, 0));
    cin >> sx >> sy;
    cin >> gx >> gy;
    cin >> n;
    int dd[] = {4, 2};
    for(int i = 0;i < n;i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      for(int xx = x; xx < x + dd[d];xx++) {
        for(int yy = y;yy < y + dd[d ^ 1];yy++) {
          field[xx][yy] = c;
        }
      }
    }
    if(field[sx][sy] == 0) {
      cout << "NG" << endl;
      continue;
    }
    dfs(sx, sy, field[sx][sy]);
    if(field[gx][gy] == -1) {
      cout << "OK" << endl;
    }
    else {
      cout << "NG" << endl;
    }
  }
}


