#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int,int> P;

const int INF=1<<30;
//const long long int INF_=1<<60;

bool compare(const pair<int,string> &p1,const pair<int,string> &p2){
	if(p1.F_>p2.F_) return true;
	else if(p1.F_<p2.F_) return false;
	else return p1.S_<p2.S_;
}

int main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int N;
    while(cin >> N&&N){
		cin.ignore();
		map<string,int> cnt;
		vector<string> str;
		REP(i,0,N){
			string sentence;
			getline(cin,sentence);
			stringstream ss(sentence);
			while(!ss.eof()){
				string tmp;
				ss >> tmp;
				++cnt[tmp];
				if(cnt[tmp]==1) str.push_back(tmp);
				ss.ignore();
			}
		}
		char initial;
		cin >> initial;
		vector<pair<int,string> > ans;
		for(auto it=cnt.begin(); it!=cnt.end(); ++it) ans.push_back(make_pair(it->S_,it->F_));
		sort(ans.begin(),ans.end(),compare);
		int k=0;
		REP(i,0,ans.size()) if(k<5&&ans[i].S_[0]==initial){
			if(k) cout << ' ';
			cout << ans[i].S_;
			++k;
		}
		if(!k) cout << "NA";
		cout << endl;
	}
	return 0;
}