#include<bits/stdc++.h>

using namespace std;

string LineData;
vector<pair<string, int> > WordsInfo;
vector<pair<string, int> >::iterator it;


void solve() {
	string word;
	stringstream ss(LineData);
	
	while (ss>>word) {
		//cout << word << " ";
		for (it = WordsInfo.begin(); it != WordsInfo.end(); ++it) {
			if (it->first == word) {
				++it->second;
				break;
			}
		}
		if (it == WordsInfo.end()) {
			WordsInfo.push_back(make_pair(word, 1));
		}
	}
}

bool cmp(const pair<string, int>& w1, const pair<string, int>& w2) {
	if (w1.second == w2.second) {
		return w1.first < w2.first;
	}
	return w1.second > w2.second;
}

bool matchWords(char target) {
	
	for (it = WordsInfo.begin(); it != WordsInfo.end();) {
		if (it->first[0] != target) {
			it = WordsInfo.erase(it);
			continue;
		}
		++it;
	}

	if (WordsInfo.empty()) {
		return false;
	}
	sort(WordsInfo.begin(), WordsInfo.end(), cmp);
	return true;
}

void show() {
	int cnt;

	cnt = WordsInfo.size() > 5 ? 5 : WordsInfo.size();
	for (int i = 0; i < cnt; ++i) {
		if (i != 0) {
			cout << " ";
		}
		cout << WordsInfo[i].first;
	}
	cout << endl;
}

int main() {
	int n;
	char target;

	while (cin >> n, n) {
		getchar();
		WordsInfo.clear();
		for (int i = 0; i < n; ++i) {
			getline(cin, LineData);
			//cout << LineData << endl;
			solve();
		}
		cin >> target;
		//cout << "target:" << target << endl;
		if (matchWords(target)) {
			show();
		}
		else {
			cout << "NA" << endl;
		}
	}

	return 0;
}

