#include <iostream>
#include<string>
using namespace std;
struct be
{
string a;
string b;
};
int main()
{
int n;
cin >> n;
be a[150];
for (int i = 0; i < n; i++)
cin >> a[i].a >> a[i].b;
string s;
cin >> s;
int l = 0;
int first = 0;
for (int i = 0; i < s.size(); i++)
{
if (s[i] >= 'a' && s[i] <= 'z')
l++;
else if(l>0)
{
string str = s.substr(first, l);
bool flag = 1;
for (int j = 0; j < n; j++)
{
if (str == a[j].a)
{
if(str.size()>a[j].b.size())
i=i-(str.size()-a[j].b.size());
else
i=i+(a[j].b.size()-str.size());
s.replace(first, l, a[j].b);
flag = 0;
break;
}
}
if (flag)
s.replace(first, l,"UNK");
first = i + 1;
l = 0;
}
else
{
first=i+1;
}
}
string str = s.substr(first, l);
bool flag = 1;
for (int j = 0; j < n; j++)
{
if (str == a[j].a)
{
s.replace(first, l, a[j].b);
flag = 0;
break;
}
}
if (flag)
s.replace(first, l,"UNK");
cout << s;
return 0;
}