#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <tuple>

using namespace std;

class Solver {
};
int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;


		char dum;
		cin >> dum;
		map<string, int> mp;
		for (int i = 0; i < n; i++) {
			string line;
			getline(cin, line);
			string ss = "";
			if (i == 0)ss += dum;
			for (int j = 0; j < line.size(); j++) {
				if (line[j] == ' ') {
					if (mp.find(ss) == mp.end()) {
						mp.emplace(ss, 0);
					}
					mp[ss]++;
					ss = "";
				}
				else {
					ss += line[j];
				}
			}
			if (mp.find(ss) == mp.end()) {
				mp.emplace(ss, 0);
			}
			mp[ss]++;
		}

		char c;
		cin >> c;
		vector<tuple<int, string>> strs;
		for (auto pair : mp) {
			if (pair.first[0] == c) {
				strs.emplace_back(make_tuple(-pair.second, pair.first));
			}
		}

		if (strs.size() == 0) {
			cout << "NA" << endl;
		}
		else {
			sort(strs.begin(), strs.end());
			int cnt = 5;
			if (strs.size() < cnt)cnt = strs.size();
			for (int i = 0; i < cnt; i++) {
				cout << get<1>(strs[i]);
				if (i+1 < cnt)cout << " ";
			}
			cout << endl;
		}
	}
}
