Infinity = 1000000

def bellman graph, s
  n = graph.size
  dist = Array.new(n, Infinity)
  dist[s] = 0

  #始点以外のすべての点について最短経路計算を行う
  (1..n).each do |u|
    #すべての辺をもとに最短経路を更新
    n.times do |i|
      graph[i].each do |v|
        newLength = dist[i] + 1
        if newLength < dist[v]
           raise Exception.new("negative cycle found.") if i == n
          dist[v] = newLength
        end
      end
    end
  end
  dist
end

#ネットワーク取得
n = $stdin.gets.to_i
graph = Array.new(n).map{Array.new}
n.times do
  input = $stdin.gets.split(" ").map(&:to_i)
  input[1].times do |t|
    graph[input[0] - 1] << input[t + 2] - 1
  end
end

#パケット処理
$stdin.gets.to_i.times do
  s, d, v = $stdin.gets.split(" ").map(&:to_i)
  dist = bellman(graph, s - 1)
  if dist[d - 1] + 1 <= v
    puts dist[d - 1] + 1
  else
    puts "NA"
  end
end