while true
    n = gets.to_i
    break if n == 0
    arr = []
    n.times{arr << gets.chomp.split}
    k = gets.chomp
    h = Hash.new(0)
    arr.each{|ar| ar.each{|word| h[word] += 1 if word[0] == k}}
    answer = []
    h.sort_by{|k, v| [-v, k]}[0, 5].each{|k, v| answer << k}
    puts (answer.length == 0 ? "NA" : answer.join(" "))
end

