#include <cstdio>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iostream>
using namespace std;
typedef pair<string,int> P;
bool compare(const P &p1,const P &p2) {
	if(p1.second!=p2.second) {
		return p1.second>p2.second;
	}else {
		return p1.first<p2.first;
	}
}
int main() {
	int n;
	while(cin>>n,n) {
		getchar();
		map<string,int> m[26];
		string x,y,z;
		for(int i=0;i<n;i++) {
			getline(cin,x);
			stringstream sstr(x);
			while(getline(sstr,y,' ')) {
				m[y[0]-'a'][y]++;
			}
		}
		cin>>z;
		int k=z[0]-'a';
		if(m[k].empty()) {
			cout<<"NA"<<endl;
		}else {
			vector<P> V;
			for(map<string,int>::iterator itr=m[k].begin();itr!=m[k].end();itr++) {
				V.push_back(*itr);
			}
			sort(V.begin(),V.end(),compare);
			cout<<(V[0].first);
			for(int i=1;i<min(5,(int)V.size());i++) {
				cout<<" "<<(V[i].first);
			}
			cout<<endl;
		}
	}
}