// AOJ 0242
#include<algorithm>
#include<iostream>
#include<map>
#include<sstream>
#include<string>
#include<vector>
#define rep(i,a) for( int i = 0; i != (a); ++i )

typedef std::pair<int, std::string> P;

int main()
{
	int n;
	while( std::cin >> n, n )
	{
		std::map<std::string, int> m;

		std::cin.ignore();
		rep( i, n )
		{
			std::string s;
	
			std::getline( std::cin, s );
		
			std::istringstream iss( s );
			std::string t;
			while( iss >> t )
				--m[t];
		}

		std::string ch;
		std::cin >> ch;

		std::map<std::string, int>::iterator it = m.lower_bound( ch );
		std::vector<P> v;
		int cnt = 0;

		if( it != m.end() && it->first[0] == ch[0] )
			v.push_back( std::make_pair( it->second, it->first ) ), ++it, ++cnt;

		for( ; it != m.end() && it->first[0] == ch[0] && cnt != 5; ++it )
			v.push_back( std::make_pair( it->second, it->first ) ), ++cnt;
		
		if( !cnt )
			std::cout << "NA" << std::endl;
		else
		{
			std::sort( v.begin(), v.end() );

			rep( i, v.size() )
				std::cout << v[i].second << " \n"[i==v.size()-1];
		}
	}

	return 0;
}