s=["a"]
for i in 1.. 25
  s.push(s[i-1].next)
end

while true
  n=gets.to_i
  d=Array.new(26)
  for i in 0.. 25
    d[i] = []
  end
  if n==0 then break end
  for i in 0.. n-1
    line = gets.chomp.split(/ /)
    for j in 0.. line.length-1
      d[s.index(line[j][0])].push(line[j])
    end
  end
  a = d[s.index(gets.chomp)]
  if a==nil
    puts "NA"
  else
    puts a.uniq.sort*" "
  end
end