Infinity = 1000000

def floydwarshall graph
  n = graph.size
  dist = Array.new(n).map{Array.new(n, Infinity)}
  n.times do |i|
    dist[i][i] = 0
  end
  n.times do |i|
    graph[i].each do |edge|
      dist[i][edge] = 1
    end
  end

  n.times do |k|
    n.times do |u|
      n.times do |v|
        newPop = dist[u][k] + dist[k][v]
        if newPop < dist[u][v]
          dist[u][v] = newPop
        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

dist = floydwarshall graph

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