def g;gets.split.map &:to_i;end
r=1..n=g[0]
w=[0]+r.map{[0]+[1e9]*n}
r.map{f,_,*t=g;t.map{|i|w[f][i]=1}}
r.map{|k|r.map{|i|r.map{|j|(a=(b=w[i])[k]+w[k][j])<b[j]&&b[j]=a}}}
g[0].times{s,d,v=g;puts v<(c=w[s][d]+1)?:NA:c}