#include<iostream>
#include<string>
#include<cstdio>
#include<map>
#include<sstream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  string str;
  int n;
  while(cin >> n && n){
    map<string,int> data;
    vector<pair<int,string> > v;
    char c;
    bool flg = false;
    getchar();
    while(n--){
      getline(cin,str);
      stringstream ss(str);
      while(ss >> str)data[str]++;
    }
    cin >> c;
    for(map<string,int>::iterator i=data.begin(),l=data.end();i!=l;i++){
      if(c==i->first[0]){
	v.push_back(make_pair(-i->second,i->first));
      }
    }
    sort(v.begin(),v.end());

    if(v.empty()) cout << "NA" << endl;
    else {
      for(int i=0,l=v.size();i<l&&i<5;i++){
	if(flg)cout << " ";
	else flg = true;
	cout << v[i].second;
      }
      cout << endl;
    }
  }
}