#include <iostream>
#include <map>
#include <string>
#include <cctype>
using namespace std;
int main() {
int n;
cin >> n;
map<string, string> dict;
for (int i = 0; i < n; i++) {
string a, b;
cin >> a >> b;
dict[a] = b;
}
string s;
cin.ignore();
getline(cin, s);
string r = "";
string cn = "";
for (char c : s) {
if (c >= 'a' && c <= 'z') {
cn += c;
} else {
if (!cn.empty()) {
if (dict.find(cn) != dict.end()) {
r += dict[cn];
} else {
r += "UNK";
}
cn = "";
}
r += c;
}
}
if (!cn.empty()) {
if (dict.find(cn) != dict.end()) {
r += dict[cn];
} else {
r += "UNK";
}
}
cout << r << endl;
return 0;
}