#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef pair<int ,string> pis;
 
 
const int INF = 10000000;


vector<string> split(const string &s, char c = ' '){
	vector<string> ret;
	stringstream ss(s);
	string t;
	while(getline(ss,t,c)){
		ret.pb(t);
	}
	return ret;
}


int main(){
	int n;
	string s;
	char c;
	while(cin>>n && n > 0){
		cin.ignore();
		map<string, int> m;
		rep(i,n){
			getline(cin, s);
			vector<string> v = split(s);
			rep(j, v.size()) m[v[j]]++;
		}
		cin>>c;
		vector<pair<int,string> > v;
		for(auto it = m.begin(); it != m.end(); it++){
			if(it->fi[0] == c) v.pb(pis(-it->se, it->fi));
		}
		sort(all(v));
		for(int i = 0; i < min((int)v.size(), 5); i++){
			if(i != 0) cout<<" ";
			cout<<v[i].se; 
		}
		if(v.size() == 0) cout<<"NA";
		cout<<endl;
	}
}