#include<iostream>
#include<vector>
using namespace std;

struct Info
{
    string word;
    int cnt;
};

int main()
{
    int n;
    char c;

    while( cin >> n )
    {
        if( !n )
            break;

        string s;
        vector<string> v;

        getline( cin, s );
        for( int i = 0; i < n; i++ )
        {
            getline( cin, s );

            s += " ";
            string t = "";
            for( int j = 0; j < s.size(); j++ )
            {
                if( s[j] == ' ' )
                {
                    v.push_back( t );
                    t = "";
                    continue;
                }
                t += s[j];
            }
        }

        cin >> c;

        vector<Info> w;

        for( int i = 0; i < v.size(); i++ )
            if( c == v[i][0] )
            {
                Info x;
                x.word = v[i];
                x.cnt = 0;

                bool judge = true;
                for( int j = 0; j < w.size(); j++ )
                    if( w[j].word == v[i] )
                    {
                        w[j].cnt++;
                        judge = false;
                        break;
                    }

                if( judge )
                    w.push_back( x );
            }

        for( int i = 0; i < w.size(); i++ )
            for( int j = w.size() - 1; j > i; j-- )
                if( w[j].cnt > w[j-1].cnt )
                {
                    Info temp = w[j];
                    w[j] = w[j-1];
                    w[j-1] = temp;
                }

        for( int i = 0; i < w.size(); i++ )
            for( int j = w.size() - 1; j > i; j-- )
                if( w[j].cnt == w[j-1].cnt && w[j].word < w[j-1].word )
                {
                    Info temp = w[j];
                    w[j] = w[j-1];
                    w[j-1] = temp;
                }
        if( w.size() == 0 )
            cout << "NA" << endl;
        else
        {
            cout << w[0].word;
            for( int i = 1; i < 5 && i < w.size(); i++ )
                cout << " " << w[i].word;
            cout << endl;  
        }
    }
    return 0;
}
