import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.typecons;


alias Tuple!(int, string) P;

void main()
{
  for(int n; (n = to!int(chomp(readln()))) != 0; ){
    int[string] hash;

    foreach(i; 0..n){
      foreach(word; split(chomp(readln()))){
        hash[word]++;
      }
    }

    char k = to!char(chomp(readln()));
    P array[];

    foreach(word, count ; hash){
      if(word[0] == k){
    	array ~= tuple(count, word);
      }
    }

    sort!((P a, P b){ return a[1] < b[1] || (a[1] == b[1] && a[0] > b[0]); })(array);

    bool flag =	true;
    int	up = min(cast(int)array.length, 5);
    foreach(i; 0..up){
      writef("%s%c", array[i][1], (i + 1 == up ? '\n' : ' '));
      flag = false;
    }

    if(flag) writeln("NA");
  }
}

int min(int a, int b)
{ return a > b ? b : a; }