#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <complex>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i:a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

//文字列分割
VS split(string str, char del) {
	VS re;
	string sub;
	for (char c : str) {
		if (c == del) {
			re.pb(sub);
			sub.clear();
		}
		else {
			sub += c;
		}
	}
	re.pb(sub);
	return re;
}

int main() {
	while (true) {
		int n; cin >> n;
		if (n == 0)break;
		n++;
		VS line(n); rep(i, n)getline(cin, line[i]);
		char k; cin >> k;

		VS a;
		rep(i, n) {
			VS tmp = split(line[i], ' ');
			a.insert(a.end(), all(tmp));
		}

		vector<pair<int, string>> ans;
		rep(i, sz(a)) {
			if (a[i][0] == k) {

				bool flag = false;
				rep(j, sz(ans)) {
					if (ans[j].second == a[i])ans[j].first++, flag = true;
				}
				if (!flag)ans.pb(mp(1, a[i]));

			}
		}
		rep(i, sz(ans))ans[i].first = 100 - ans[i].first;
		SORT(ans);

		if (ans.empty())puts("NA");
		else {
			rep(i, min(5, sz(ans))) {
				cout << ans[i].second;
				printf(i == min(5, sz(ans)) - 1 ? "\n" : " ");
			}
		}
	}
}
