#include <bits/stdc++.h>
using namespace std;
struct stu
{
string word;
int idx;
} a[102],b[102];
int main()
{
int n;
cin>>n;
for (int i=0;i<n;i++)
{
cin>>a[i].word>>b[i].word;
}
string s,s2 = "", w = "";
cin>>s;
s+=' ';
bool is = 0;
for (int i = 0; i < s.size(); i++)
{
if (s[i] >= 'a' && s[i] <= 'z')
{
w += s[i];
}
else
{
is = 0;
for (int j = 1; j <= n; j++)
{
if (w == a[j].word)
{
is = 1;
w = b[j].word;
break;
}
}
if (is)
s2 += w;
else if (w!= "")
s2 += "UNK";
if (s[i] < 'a' || s[i] > 'z')
{
s2+=s[i];
}
w="";
}
}
cout<<s2;
return 0;
}