### main

while true
  n = gets.strip.to_i
  break if n == 0

  words = []
  hists = {}

  n.times do
    ws = gets.strip.split(' ')

    for w in ws
      if hists[w].nil?
        words << w
        hists[w] = 1
      else
        hists[w] += 1
      end
    end
  end
  #p words
  #p hists

  k = gets.strip

  kwords = words.select{|w| w[0] == k}.sort{|a, b|
    (cmp = hists[b] <=> hists[a]) != 0 ? cmp : a <=> b
  }[0, 5]
  #p kwords

  puts(kwords.empty? ? 'NA' : kwords.join(' '))
end