#include <bits/stdc++.h>
using namespace std;

typedef struct{
  int cnt;
  string str;
} Moji;

bool asc(const Moji& left,const Moji& right){
  return left.cnt == right.cnt ? left.str < right.str : left.cnt > right.cnt;
}


int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0) break;

    string tmptmp;
    getline(cin,tmptmp);
    map<string,int> mp;
    Moji moji[26][5000];
    int mjp[26] = {};
    for(int i = 0;i < n;i++){
      string s,tmp;

      getline(cin,s);
      for(int i = 0;i < s.size();i++){
        if(s[i] == ' '){
          if(mp[tmp] == 0){
            moji[tmp[0]-'a'][mjp[tmp[0]-'a']].str = tmp;
            mjp[tmp[0]-'a']++;
          }
          mp[tmp]++;
          tmp.clear();
        }else{
          tmp.push_back(s[i]);
        }
      }
      if(mp[tmp] == 0){
        moji[tmp[0]-'a'][mjp[tmp[0]-'a']].str = tmp;
        mjp[tmp[0]-'a']++;
      }
      mp[tmp]++;
    }
    char search;
    cin >> search;
    search-='a';

    if(mjp[search] == 0){
      cout << "NA" << endl;
    }else{
      for(int i = 0;i < mjp[search];i++){
        moji[search][i].cnt = mp[moji[search][i].str];
      }
      sort(moji[search],moji[search]+mjp[search],asc);

      for(int i = 0;i < min(5,mjp[search]);i++){
        cout << moji[search][i].str; if(i != min(5,mjp[search])-1) cout << " "; else cout << endl;
      }
    }
  }

  return 0;
}






