root=(1..gets.to_i).map{
  r,k,*t=gets.split.map(&:to_i)
  [r,t]
}.to_h

gets.to_i.times{
  s,d,v=gets.split.map(&:to_i)
  q=[[s,1]]
  ret = while q[0]
    id,num=q.shift
    break num if id==d
    next if num>=v
    root[id].each{|i|
      q.push([i,num+1])
    }
  end
  puts (ret||"NA")
}