Infinity = 1000000

def dijkstra graph, s
  n = graph.size
  dist = Array.new(n, Infinity)
  visited = Array.new(n, false)
  dist[s] = 0
  loop do
    min = -1
    sd = Infinity
    n.times do |i|
      if (! visited[i]) && dist[i] < sd
        min = i
        sd = dist[i]
      end
    end
    break if min == -1
    visited[min] = true
    graph[min].each do |node|
      newLen = dist[min] + 1
      if(newLen < dist[node])
        dist[node] = newLen
      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 = dijkstra(graph, s - 1)
  if dist[d - 1] + 1 <= v
    puts dist[d - 1] + 1
  else
    puts "NA"
  end
end