#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        string in;
        getline(cin, in);
        map<string, int> mp;
        set<string> st;
        rep(i, n){
            getline(cin, in);
            int j = 0;
            rep(k, in.size()){
                if(in[k] == ' '){
                    mp[in.substr(j, k-j)]--;
                    st.insert(in.substr(j, k-j));
                    j = k+1;
                }else if(k == in.size()-1){
                    k++;
                    mp[in.substr(j, k-j)]--;
                    st.insert(in.substr(j, k-j));
                }
            }
        }
        char c;
        cin >> c;
        priority_queue< pair<int, string>, vector< pair<int, string> >, greater< pair<int, string> > > que;
        for(auto x = st.begin() ; x != st.end() ; x++){
            string tmp = *x;
            if(tmp[0] == c){
                que.push(make_pair(mp[tmp], tmp));
            }
        }
        if(que.empty()){
            cout << "NA" << endl;
        }else{
            int cnt = 0;
            while(!que.empty() && cnt < 5){
                cout << que.top().second;
                que.pop();
                cnt++;
                if(que.empty() || cnt == 5){
                    cout << endl;
                }else{
                    cout << " ";
                }
            }
        }
    }
    return 0;
}
