#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int n;
	while(cin>>n,n){
		cin.ignore();
		map<string,int> data;
		data.clear();
		while(n--){
			/*cout <<"popopo"<<endl;
			cout <<endl;*/
			string str;
			getline(cin,str);
			//cout <<str<<endl;
			string tmp="";
			for(int i=0;i <str.length();i++){
				if(str[i]==' '||i==str.length()-1){
					//cout <<tmp<<endl;
					if(i==str.length()-1)tmp+=str[i];
					data[tmp]++;
					tmp ="";
				}else{
					tmp+=str[i];
				}
			}
		}
		char c;
		cin>>c;
		vector<pair<int,string> > d;
		d.clear();
		map<string,int>:: iterator it =data.begin();
		while(it!=data.end()){
			string a =(*it).first;
			int cnt =(*it).second;
			//cout <<a<<endl;
			if(a[0]==c){
				d.push_back(mp(-cnt,a));
			}
			it++;
		}
		sort(d.begin(),d.end());
		bool flag =false;
		for(int i =0;i<d.size()&&i <5;i++){
			flag=true;
			if(i!=0)cout <<" "<<d[i].second;
			else cout <<d[i].second;
		}
		if(flag)cout <<endl;
		else cout <<"NA"<<endl;
	}
	return 0;
}