#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

struct Info{
	Info(){
		num = 0;
	}
	char word[21];
	int num;
};

//base??¨comp??????????????????????????¢??°
bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

//???????????????????????????3,left?????????????????´??????1,right?????????????????¨??????2
int strCmp2(char* left,char* right){
	int i;

	if(strCmp(left,right))return 3;

	for(i=0;left[i] != '\0' && right[i] != '\0'; i++){
		if(left[i] != right[i]){
			if(left[i] < right[i])return 1;
			else{
				return 2;
			}
		}
	}
	if(left[i] == '\0')return 1;
	else{
		return 2;
	}
}


int main(){

	Info** info = (Info**)malloc(sizeof(Info*)*26);
	for(int i = 0; i < 26; i++){
		info[i] = (Info*)malloc(sizeof(Info)*10000);
	}

	char buf[2050],work[21],key[2];
	bool Found;

	int n,index,num_of_each[26],tmp,limit;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i = 0; i < 26; i++){
			for(int k = 0; k < 10000;k++)info[i][k].num = 0;
			num_of_each[i] = 0;
		}

		getchar();

		for(int i = 0; i < n; i++){
			fgets(buf,2050,stdin);

			index = 0;
			for(int k = 0; buf[k] != '\n' && buf[k] != '\0';k++){
				if(buf[k] == ' '){
					//??¢???????????°????¢?????????????????????????num???1??§????????????
					tmp = work[0] - 'a'; //????????????????????????

					if(num_of_each[tmp] == 0){
						info[tmp][0].num = 1;
						strcpy(info[tmp][0].word,work);
						num_of_each[tmp]++;
					}else{
						Found = false;
						for(int p = 0; p < num_of_each[tmp];p++){
							//??¢????????´???
							if(strCmp(work,info[tmp][p].word)){
								info[tmp][p].num++;
								Found = true;
								break;
							}
						}
						if(!Found){
							info[tmp][num_of_each[tmp]].num = 1;
							strcpy(info[tmp][num_of_each[tmp]].word,work);
							num_of_each[tmp]++;
						}
					}
					index = 0;
				}else{
					work[index++] = buf[k];
					work[index] = '\0';

					if(buf[k+1] == '\0' || buf[k+1] == '\n'){
						//??¢???????????°????¢?????????????????????????num???1??§????????????
						tmp = work[0] - 'a';
						if(num_of_each[tmp] == 0){
							info[tmp][0].num = 1;
							strcpy(info[tmp][0].word,work);
							num_of_each[tmp]++;
						}else{
							Found = false;
							for(int p = 0; p < num_of_each[tmp];p++){
								//??¢????????´???
								if(strCmp(work,info[tmp][p].word)){
									info[tmp][p].num++;
									Found = true;
									break;
								}
							}
							if(!Found){
								info[tmp][num_of_each[tmp]].num = 1;
								strcpy(info[tmp][num_of_each[tmp]].word,work);
								num_of_each[tmp]++;

							}
						}
					}
				}
			}
		}
		scanf("%s",key);

		tmp = key[0] - 'a';

		limit = num_of_each[tmp];

		for(int i = 1; i <= limit-1; i++){
			for(int k = limit-1; k >= i; k--){
				if(info[tmp][k].num > info[tmp][k-1].num)swap(info[tmp][k],info[tmp][k-1]);
				else if(info[tmp][k].num == info[tmp][k-1].num && strCmp2(info[tmp][k].word,info[tmp][k-1].word) == 1)swap(info[tmp][k],info[tmp][k-1]);
			}
		}

		for(int i = 0; i < min(limit,5); i++){
			if(i == 0)printf("%s",info[tmp][i].word);
			else{
				printf(" %s",info[tmp][i].word);
			}
		}
		if(limit!=0)printf("\n");
		if(limit == 0)printf("NA\n");
	}

    return 0;
}

Measured memory_bytes: 10356