#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
bool cmp(const pair<int,string> &a,const pair<int,string> &b){
    return a.F!=b.F?a.F>b.F:a.S<b.S;
}
int main(){
    map<string,int> s[26];
    string c,temp;
    vector<pair<int,string>> ans;
    int n;
    while(true){
        getline(cin,c);
        n=0;
        for(int i=0;i<c.size();i++){
            n*=10;
            n+=c[i]-'0';
        }
        if(n==0)return 0;
        for(int i=0;i<26;i++)s[i].clear();
        while(n--){
            getline(cin,c);
            temp.clear();
            for(int i=0;i<c.size();i++){
                if(c[i]==' '){
                    if(s[temp[0]-'a'].find(temp)==s[temp[0]-'a'].end())s[temp[0]-'a'].insert(MP(temp,1));
                    else s[temp[0]-'a'][temp]++;
                    temp.clear();
                }
                else temp+=c[i];
            }
            if(s[temp[0]-'a'].find(temp)==s[temp[0]-'a'].end())s[temp[0]-'a'].insert(MP(temp,1));
            else s[temp[0]-'a'][temp]++;
        }
        getline(cin,c);
        if(s[c[0]-'a'].empty())cout<<"NA\n";
        else{
            ans.clear();
            for(auto u: s[c[0]-'a'])ans.PB(MP(u.S,u.F));
            sort(ans.begin(),ans.end(),cmp);
            cout<<ans[0].S;
            for(int i=1;i<min(static_cast<int>(ans.size()),5);i++)cout<<" "<<ans[i].S;
            cout<<"\n";
        }
    }
}
