#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

#include <cstdlib>
#include <map>
#include <algorithm>
#include <queue>

#include <iostream>
#include <sstream>
#include <cstdio>
#include <set>

#define REP(i,n) for(int i=0; i<(int)(n); i++)
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int main(){
  while(true){
    map<string, int> m;
    string str, s;

    getline(cin, str);
    const int n = atoi(str.c_str());
    if(n == 0) break;

    REP(i,n){

      getline(cin, str);
      stringstream ss(str);

      while(ss >> s){
        m[s]++;
      }
    }

    string c; getline(cin, c);

    vector<pair<int, string> > ans;

    FOR(it, m){
      if(it->first[0] == c[0]){
        ans.push_back(make_pair(-it->second, it->first));
      }
    }

    sort(ans.begin(), ans.end());

    REP(i,min(5, (int)ans.size())){
      if(i != 0) cout << " ";
      cout << ans[i].second;
    }

    if(ans.size() == 0) cout << "NA";
    cout << endl;
  }

  return 0;
}