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

int main() {
	int n;
	while (cin >> n, n) {
		cin.ignore();
		map<string,int> cnt;
		string s, word;
		for (int i=0; i<n; ++i) {
			getline(cin, s);
			stringstream ss(s);
			while (ss >> word) {
				++ cnt[word];
			}
		}
		char c;
		cin >> c;
		vector<pair<int,string> > v;
		for (auto it : cnt) {
			if (it.first[0] == c) {
				v.push_back(make_pair(-it.second, it.first));
			}
		}
		sort(v.begin(), v.end());
		if (v.empty()) {
			cout << "NA" << endl;
		} else {
			for (int i=0; i<5 && i<(int)v.size(); ++i) {
				cout << (i==0 ? "" : " ") << v[i].second;
			}
			cout << endl;
		}
	}
	return 0;
}