#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

struct P
{
    int cnt;
    string s;

    P(int cnt, string s)
    {
        this->cnt = cnt;
        this->s = s;
    }

    bool operator<(const P& p) const
    {
        if (this->cnt < p.cnt) return true;
        else if (this->cnt == p.cnt && this->s > p.s) return true;
        return false;
    }
};

int main()
{
    int n;

    while (cin >> n, n){
        map<string, int> cnt;
        set<string> word[26];
        string line;

        getline(cin, line);
        while (n-- > 0){
            getline(cin, line);
            for (int i = 0; i < line.length(); ){
                int j;
                for (j = i; 'a' <= line[j] && line[j] <= 'z'; j++);

                string s = line.substr(i, j - i);
                int index = s[0] - 'a';

                word[index].insert(s);
                cnt[s]++;

                i = j + 1;
            }
        }

        char k;
        cin >> k;
        vector<P> v;
        for (set<string>::iterator i = word[k - 'a'].begin(); i != word[k - 'a'].end(); i++){
            v.push_back(P(cnt[*i], *i));
        }

        if (v.size() == 0){
            cout << "NA\n";
            continue;
        }

        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        int size = min(v.size(), (size_t)5);
        for (int i = 0; i < size; i++){
            cout << v[i].s << "\n "[i < size - 1];
        }
    }

    return 0;
}