r=(a=(b=[-1,0,1])+[-2,2]*3+b).zip(a.sort)
while(s=gets.split.map &:to_i)[0]>0
gets
q=[s]
gets.split.map(&:to_i).each_slice(2){|i,j|q=q.flat_map{|x,y|r.map{|t,u|t+=x;u+=y
t|u>=0&&t<=9&&u<=9&&t>i-2&&t<i+2&&u>j-2&&u<j+2?[t,u]:0}}.uniq-[0]}
puts q[0]?:OK:"NA"end