object Main extends App {

  import scala.io.StdIn._

  solve
  def solve:Unit = {
    val n = readLine.trim.toInt
    if (n == 0) return
    val words = Array.tabulate(n) { _ ⇒ readLine.trim.split(' ') }.flatten.groupBy(s ⇒ s).mapValues(_.length).toArray
    val k = readLine.head
    val filtered = words.filter(_._1.head == k)
    if (filtered.isEmpty) {
      println("NA")
    }else{
      val w = filtered.sortWith((a, b) ⇒ if (a._2 == b._2) a._1 < b._1 else a._2 > b._2).map(_._1)
      if (w.length > 5) println(w.take(5).mkString(" "))
      else println(w.mkString(" "))
    }
    solve
  }
  implicit class Extension[T](val value :T) extends AnyVal {
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}
