#include
#include
#include
#include
#include
int main (){
freopen ("input.txt", "r", stdin);
freopen ("output.txt", "w", stdout);
int n;
std::cin >> n;
std::set seps;
char * s = new char[256];
std::cin.getline(s, n * 2);
std::cin.getline(s, n * 2);
for (int i = 0; i < n; i++){
seps.insert (s[i*2]);
}
int x;
std::cin >> x;
std::vector> text;
std::cin.getline(s, 100);
int wordsCount = 0;
do {
char * str = new char[256];
char c;
int i = 0, count = 0;
bool del = false;
std::set s;
while ((c = getchar()) != '\n'){
str[i++] = c;
if (seps.find(c) != seps.end()){
count++;
if (s.find(c) != s.end()) del = true;
else s.insert(c);
}
};
str[i++] = '\0';
if (!del) text.push_back (std::make_pair(count, str));
wordsCount += count + 1;
} while (wordsCount <= x);</span>
sort (text.begin(), text.end());
for (int i = 0; i < text.size(); i++)
std::cout << text[i].second << "\n";</span>
}