#include<iostream>
#include<cstdio>
using namespace std;
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define rep(i,a) for(int i = 0 ; i < a ; i ++)

int maze[104][104];
int h,w;
int sx,sy ,  gx,gy , n;
int co;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};

bool inmaze(int x,int y){
  return (0<=x && x<w) && (0<=y && y<h);
}

bool dfs(int x,int y){
  //cout<<"che"<<x<<" "<<y<<endl;
  if(x == gy && y == gx){
    return true;
    cout<<"ok"<<endl;
  }
  if(!inmaze(x,y))return false;
  maze[x][y] = 10;
  bool res = false;
  rep(i,4)
    if(maze[x + dx[i]][y + dy[i]] == co){
      res = dfs(x+dx[i],y+dy[i]);
      if(res)return true;
    }
  return res;
}

int main(void){
  while(cin>>w>>h,w+h){
    cin>>sx>>sy>>gx>>gy>>n;
    sx--,sy--,gx--,gy--;
    //cout<<sx<<" "<<sy<<" "<<gx<<" "<<gy<<endl;
    rep(i,h)rep(j,w)maze[i][j] = -1;
    rep(i,n){
      int c,b,x,y;
      cin>>c>>b>>x>>y;
      x--,y--;
      //cout<<x<<" "<<y<<endl;
      rep(i,(b?2:4))
	rep(j,(b?4:2))
	maze[i+x][j+y] = c;
    }
    co = maze[sx][sy];
    bool res = dfs(sx,sy); 
    cout<<(res?"OK":"NO")<<endl;
   
  }
}