# include <bits/stdc++.h>
using namespace std;
string s;
int n;
string p = "-!()-.[].{}\\|;:\'\",./?<>";
string str_dict[101][2]; // 0 A 1 B
int main () {
cin >> n;
for (int i = 0;i < n;i ++)cin >> str_dict[i][0] >> str_dict[i][1];
cin >> s;
string t;
int index = 0;
for (int i = 0;i < s.size();i ++){
if (s.size() - 1 == i){
t = s.substr(index,i - index + 1);
bool rrr = 0;
for (int d = 0;d < n;d ++){
if (str_dict[d][0] == t){
rrr = 1;
cout << str_dict[d][1];
break;
}
}
if (rrr == 0)cout << "UNK";
break;
}
for (int j = 0;j < p.size();j ++){
if (s[i] == p[j]){
t = s.substr(index,i - index);
index = i + 1;
bool rrr = 0;
for (int d = 0;d < n;d ++){
if (str_dict[d][0] == t){
rrr = 1;
cout << str_dict[d][1];
break;
}
}
if (rrr == 0 and t.size() != 0)cout << "UNK";
cout << s[i];
break;
}
}
}
return 0;
}