#include <iostream>
#include <queue>
#include <string>
using namespace std;
const int dx[12]={2, 2, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2};
const int dy[12]={0, 1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -1};
struct DATA {
int x, y, number;
DATA(int a, int b, int c) {x=a; y=b; number=c;}
};
bool field[10][10][10];
bool BFS(int p_x, int p_y, int s_number) {
int pos_x, pos_y, now;
queue<DATA> que;
que.push( DATA(p_x,p_y,0) );
while ( !que.empty() ) {
DATA data=que.front(); que.pop();
pos_x=data.x; pos_y=data.y; now=data.number;
if (now == s_number) return true;
for (int k=0; k<12; ++k)
if (0<=pos_y+dy[k] && pos_y+dy[k]<10 && 0<=pos_x+dx[k] && pos_x+dx[k]<10 && field[now][ pos_y+dy[k] ][ pos_x+dx[k] ]) que.push( DATA(pos_x+dx[k],pos_y+dy[k],now+1) );
}
return false;
}
void Slove(int p_x, int p_y) {
int s_number, s_x, s_y;
for (int k=0; k<10; ++k)
for (int i=0; i<10; ++i)
for (int j=0; j<10; ++j)
field[k][i][j]=false;
cin >> s_number;
for (int k=0; k<s_number; ++k) {
cin >> s_x >> s_y;
for (int i=-1; i<=1; ++i)
for (int j=-1; j<=1; ++j)
if (0<=s_y+i && s_y+i<10 && 0<=s_x+j && s_x+j<10) field[k][s_y+i][s_x+j]=true;
}
cout << (BFS(p_x,p_y,s_number)? "OK" : "NA") << endl;
}
int main(void) {
int p_x, p_y;
while ( cin >> p_x >> p_y && (p_x || p_y) )
Slove(p_x,p_y);
return 0;
}
幅優先探索で解いた。スプリンクラーが重複とは知らず書きなおした。