#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n;
string a[114],b[514],c,d;
int main() {
cin>>n;
for(int i=0; i<n; ++i) {
cin>>a[i]>>b[i];
}
cin>>c;
c+='#';
bool emp=true;
for(int i=0; i<c.size(); ++i) {
emp=false;
if(c[i]>='a'&&c[i]<='z') {
d+=c[i];
} else {
if(!emp){
for(int j=0; j<n; ++j) {
if(d==a[j]) {
emp=true;
cout<<b[j];
d="";
break;
}
}
if(!emp)cout<<"UNK";
}
if(c[i]!='#')
cout<<c[i];
}
}
return 0;
}