#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
int main(){
int n,num,count = 0;
scanf("%d\n",&n);
/*word表示查找的单词*/
string word;
/*输入的n个单词*/
string *str = new string[n];
int flag[26] = {};
int flagword[26] = {};
int *pi = new int[n];
for (int i = 0;i < n;i++)
getline(cin,str[i]);
getline(cin,word);
cin >> num;
/*对输入的字符串排序*/
for (int i = 0;i < n - 1;i++)
for (int j = 0; j < n - i - 1;j++)
if (str[j] > str[j+1]){
string temp = str[j];
str[j] = str[j+1];
str[j+1] = temp;
}
int wordlen = word.length();
int q=0,k;
/*用flag来标记,a对应flag[0],依次下去,z代表flag[26]*/
for (int i = 0; i < wordlen;i++)
flagword[word[i] - 'a']++;
for (int i = 0; i < n;i++){
memset(flag,0,26*sizeof(int));
int len = str[i].length();
for (int j = 0; j < len;j++)
flag[str[i][j] - 'a']++;
/*只有flag相同位置上的数相等时,才表示兄弟单词,但要排除自身*/
if (str[i] != word)
for (int m = 0; m < 26;m++)
if (flag[m] == flagword[m]){
k=1;
continue;
}
else{k = 0;break;}
else k = 0;
if (k == 1){
count++;
pi[q] = i;/*将兄弟单词的位置记录下来*/
q++;
}
}
cout << count<< endl<<str[pi[num-1]]<< endl;
delete[] str;
delete[] pi;
}