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

typedef pair<string, int> P;

bool compare(P a,P b){
	return a.second == b.second ? a.first < b.first : a.second > b.second;
}

int main(){
	string str,tmp;
	int n;
	char initial;
	map<string,int> m;
	vector<P> much;
	while(cin >> n,n){
		m.clear();
		much.clear();
		getline(cin,str);
		for(int i = 0;i < n;++i){
			stringstream ss;
			getline(cin,str);
			ss << str;
			while(ss >> tmp){
				++m[tmp];
			}
		}
		cin >> initial;
		map<string,int>::iterator mit;
		for(mit = m.begin();mit != m.end();++mit){
			if((*mit).first[0] == initial){
				much.push_back(make_pair((*mit).first,(*mit).second));
			}
		}
		if(much.size() != 0){
			sort(much.begin(),much.end(),compare);
			for(int i = 0;i < much.size() && i < 5;++i){
				if(i) cout << " ";
				cout << much[i].first;
			}
			cout << endl;
		}
		else cout << "NA" << endl;
	}
	return 0;
}