#include <bits/stdc++.h>
#define int long long
using namespace std;
map <string,string> dict;
signed main(){
int n;
string s,word = "",ans = "";
cin >> n;
for(int i = 1;i <= n;i++){
string a,b;
cin >> a >> b;
dict[a] = b;
}
cin >> s;
s += '.';
for(char i = 0;i < s.length();i++){
char c = s[i];
if((c >= 'a' && c <= 'z') or (c >= 'A' && c <= 'Z')) word += c;
else{
if(word != ""){
if(dict.find(word) != dict.end()) ans += dict[word];
else ans += "UNK";
}
ans += c,word = "";
}
}
for(int i = 0;i < ans.length() - 1;i++){
cout << ans[i];
}
return 0;
}