n = gets.to_i
dp = Array.new(n) { Array.new n }
n.times do |i|
  gets.split.map(&:to_i).drop(1).each {|j| dp[i][j-1] = 1 }
  dp[i][i] = 0
end
n.times do |k|
  n.times do |i|
    n.times do |j|
      dp[i][j] = dp[i][k] + dp[k][j] if dp[i][k] && dp[k][j] && (!dp[i][j] || dp[i][k] + dp[k][j] < dp[i][j])
    end
  end
end
gets.to_i.times do
  s, d, v = gets.split.map(&:to_i)
  puts dp[s-1][d-1] && dp[s-1][d-1] + 1 <= v ? dp[s-1][d-1] + 1 : 'NA'
end