require 'set'

loop do
  n = gets.to_i
  break if n==0
  num = Hash.new(0)
  hash = Hash.new{|hash,key| hash[key]=Set.new}
  n.times do
    gets.chomp.split.each do |w|
      num[w]+=1
      hash[w.split("")[0]]<<w
    end
  end
  k = gets.chomp
  if hash[k].empty?
    puts "NA"
    next
  end
  ans = hash[k].sort{|a,b|
    if num[b]!=num[a]
      num[b]-num[a]
    else
      a<=>b
    end}
  if ans.size>=5
    puts ans[0,5].join(" ")
  else
    puts ans.join(" ")
  end
end