#include <bits/stdc++.h>
using namespace std;
char ans[33];
struct trie {
trie *next[26];
bool leaf;
trie() {
memset(next, 0, sizeof next);
leaf = 0;
}
void add(char *s) {
if (*s == 0) {
leaf = 1;
return;
}
int c = *s - 'a';
if (!next[c])
next[c] = new trie();
next[c]->add(s + 1);
}
int solve(char *s, bool f) {
if (f) {
int i;
for (i = 0; i < 26 && next[i] == 0; ++i)
;
if (i == 26)
return 0;
if (leaf)
return 0;
next[i]->solve(s, 1);
cout << char(i + 'a');
return 0;
}
if (*s == 0) {
int i;
for (i = 0; i < 26 && next[i] == 0; ++i)
;
if (i == 26) {
return -1;
}
next[i]->solve(s, 1);
cout << char(i + 'a');
return 0;
}
int c = *s - 'a', ret = -1, i;
if (next[c] != 0)
ret = next[c]->solve(s + 1, 0);
if (ret == 0) {
cout << *s;
return 0;
}
for (i = 0; i < 26; ++i) {
if (i != c && next[i])
break;
}
if (i == 26)
return leaf ? 0 : -1;
ret = next[i]->solve(s, 1);
if (ret == -1)
return -1;
cout << char(i + 'a');
return 0;
}
};
int main(int argc, char **argv) {
#ifndef ONLINE_JUDGE
freopen("a.in", "r", stdin);
#endif
char s[33];
trie root;
while (1) {
gets(s);
int ln = strlen(s);
if (!ln)
break;
reverse(s, s + ln);
root.add(s);
}
while (cin >> s) {
int ln = strlen(s);
reverse(s, s + ln);
root.solve(s, 0);
cout << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNoYXIgYW5zWzMzXTsKc3RydWN0IHRyaWUgewoJdHJpZSAqbmV4dFsyNl07Cglib29sIGxlYWY7Cgl0cmllKCkgewoJCW1lbXNldChuZXh0LCAwLCBzaXplb2YgbmV4dCk7CgkJbGVhZiA9IDA7Cgl9Cgl2b2lkIGFkZChjaGFyICpzKSB7CgkJaWYgKCpzID09IDApIHsKCQkJbGVhZiA9IDE7CgkJCXJldHVybjsKCQl9CgkJaW50IGMgPSAqcyAtICdhJz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