#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;



/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/

class Data
{
public:
	
	string term;
	int freq;
	
	Data(string _term, int _freq)
	{
		term = _term;
		freq = _freq;
	}
	
	bool operator<(const Data& d) const
	{
		if (freq == d.freq) return term < d.term;
		else return freq > d.freq;
	}
};

int main()
{
	int n;
	string str;
	
	while (cin >> n, n)
	{
		cin.ignore();
		
		map<string, int> freq;
		map<char, vector<string> > dict;
		
		REP(n)
		{
			getline(cin, str);
			stringstream ss(str);
			string s;
			while (ss >> s)
			{
				freq[s]++;
			}
		}
		
		getline(cin, str);
		
		vector<Data> data;
		for (map<string, int>::iterator it=freq.begin(); it!=freq.end(); it++)
		{
			if (it->first[0] == str[0])
			{
				data.push_back(Data(it->first, it->second));
			}
		}
		
		if (data.size() == 0)
		{
			cout << "NA" << endl;
		} else {
			sort(data.begin(), data.end());
			for (int i=0; i<data.size()&&i<5; i++)
			{
				if (i != 0)
				{
					cout << " ";
				}
				cout << data[i].term;
			}
			cout << endl;
		}
	}
	
	return 0;
}