#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;
string S, T[100000], U, V[1000][1000], W[1000]; int n, cnt, cnt2, cnt3[10000], cnt4, w[1000]; char a;
int main() {
	while (true) {
		for (int i = 0; i < 1000; i++) {
			W[i] = ""; w[i] = 0; T[i] = "";
			for (int j = 0; j < 1000; j++) {
				V[i][j] = "";
			}
		}
		U = "";
		cnt2 = 0; cnt4 = 0; memset(cnt3, 0, sizeof(cnt3));
		cin >> n; cnt = 0;
		if (!n) { break; }
		for (int i = 0; i < n; i++) {
			S = "";
			while (S == "")
			{
				getline(cin, S);
			}
			S += ' ';
			for (int i = 0; i < S.size(); i++) {
				if (S[i] == ' ') { T[cnt] = U; cnt++; U = ""; }
				else { U += S[i]; }
			}
		}
		cin >> a;
		for (int i = 0; i < cnt; i++) {
			if (T[i][0] == a) { 
				W[cnt2] = T[i]; cnt2++; 
			}
		}
		if (cnt2 == 0) { cout << "NA" << endl; goto F; }
		for (int i = 0; i < cnt2; i++) {
			for (int j = 0; j < i; j++) {
				if (W[i] == W[j]) {
					w[j]++; goto E;
				}
			}
			w[i]++;
		E:;
		}
		for (int i = 0; i < cnt2; i++) {
			if (w[i] >= 1) {
				V[w[i]][cnt3[w[i]]] = W[i];
				cnt3[w[i]]++;
			}
		}
		for (int i = 0; i < 1000; i++) {
			if (cnt3[i] >= 1) {
				sort(V[i], V[i] + cnt3[i]);
			}
		}
		for (int i = 999; i >= 0; i--) {
			for (int j = 0; j < cnt3[i]; j++) {
				if (cnt4) { cout << ' '; }
				cout << V[i][j];
				cnt4++;
			}
		}
		cout << endl;
	F:;
	}
}