#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
signed main() {
	while (1) {
		int n; cin >> n;
		if (n == 0)return 0;
		string s, st; vector<string>v; set<string>ss; map<string, int>m; vector<pair<int, string>>v2;
		for (int x = 0; x <= n; x++) {
			getline(cin, s);
			if (x == 0)continue;
			for0(i, s.size()) {
				if (s[i] == ' ') {
					v.push_back(st); st = "";
				}
				else st += s[i];
			}v.push_back(st); st = "";
		}
		char ch; cin >> ch;
		for (string i : v) {
			if (i[0] == ch) {
				if (ss.find(i) == ss.end()) {
					ss.insert(i);
					m[i] = 1;
				}
				else m[i]++;
			}
		}
		for (string i : ss) v2.push_back(make_pair(-m[i], i));
		sort(v2.begin(), v2.end());
		if (v2.size() == 0)cout << "NA";
		else for0(i, min(5, (int)v2.size())) { if (i)cout << ' '; cout << v2[i].second; }
		cout << endl;
	}
}
