#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
int n;
struct Word {
    string word;
    int count;
    Word(){}
    Word(string _word,int _count){
        word=_word,count=_count;
    }
    bool operator < (const Word &a) const {
        if(a.count!=count)
        {
            return a.count<count;
        } else{
            return a.word>word;
        }
    }
};

int main(void)
{
    string s;
	string n;
    while(getline(cin,n) && n!="0") {
        vector<set<string> > appear(26);
        vector<vector<Word> > dict(26);
        for(int line=0;line<stoi(n);line++)
        {
            //if(line==0)cin.ignore();
            getline(cin,s);
            //cout << "OUT" << endl;
            //cout << s << endl;
            string nowword="";
            int len=s.size();
            //cout << s << endl;
            for(int i=0;i<len;i++) {
                if (s[i] != ' ') nowword += s[i];
                else if (s[i] == ' ') {
                    int index = int(nowword[0] - 'a');
                    auto it = appear[index].find(nowword);
                    if (it == appear[index].end()) {
                        dict[index].push_back(Word(nowword, 0));
                        appear[index].insert(nowword);
                    } else {
                        for (int j = 0; j < dict[index].size(); j++) {
                            if (dict[index][j].word == nowword)dict[index][j].count++;
                        }
                    }
                    //cout << nowword << endl;
                    nowword = "";
                }
                if (i == len - 1) {
                    int index = int(nowword[0] - 'a');
                    auto it = appear[index].find(nowword);
                    if (it == appear[index].end()) {
                        dict[index].push_back(Word(nowword, 0));
                        appear[index].insert(nowword);
                    } else {
                        for (int j = 0; j < dict[index].size(); j++) {
                            if (dict[index][j].word == nowword)dict[index][j].count++;
                        }
                    }
                    //cout << nowword << endl;
                    nowword = "";
                }
            }
        }
        string k;
    	getline(cin,k);
        int index=int(k[0]-'a');
        sort(dict[index].begin(),dict[index].end());
        int out=min(5,int(dict[index].size()));
        //cout << out << endl;
        if(out==0)
        {
            cout << "NA" << endl;
        } else {
            for (int i = 0; i < out; i++) {
                if (i != out - 1)
                {
                    cout << dict[index][i].word << ' ';
                }
                else
                {
                    cout << dict[index][i].word << endl;
                }
            }
        }
    }

  return 0;
}

