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