#include <iostream>
#include <sstream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

typedef pair<int,string> P;

int main(){
  int n;

  while(cin >> n, n){
    string s;
    getline(cin, s);

    map<string,int> cnt;

    for(int i = 0; i < n; i++){
      getline(cin, s);
      stringstream ss(s);
      string ts;

      while(ss >> ts){
	cnt[ts]++;
      }
    }

    char ch;
    cin >> ch;

    vector<P> v;

    for(map<string,int>::iterator iter = cnt.begin(); iter != cnt.end(); iter++){
      if((iter->first)[0] == ch){
	v.push_back(P(-1 * iter->second, iter->first));
      }
    }

    if(v.size() > 0){
      sort(v.begin(), v.end());
      for(int i = 0; i < min((int)v.size(), 5); i++){
	if(i != 0) cout << " ";
	cout << v[i].second;
      }
      cout << endl;
    }
    else{
      cout << "NA" << endl;
    }
  }
}