#include <bits/stdc++.h>
using namespace std;
struct dic
{
string a;
string b;
};
int w = -1;
bool bo;
const int N = 100 + 10;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
dic zd[N];
string dfe;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> zd[i].a >> zd[i].b;
}
cin >> dfe;
if(dfe[dfe.size()-1]>='a'&&dfe[dfe.size()-1]<='z')
dfe += '.';
for (int i = 0; i < dfe.size(); i++)
{
if (dfe[i] < 'a' || dfe[i] > 'z')
{
if (i-1<0||(dfe[i - 1] < 'a' || dfe[i - 1] > 'z'))
{
cout << dfe[i];
w = i;
continue;
}
for (int k = 1; k <= n; k++)
{
bo = true;
for (int j = 0; j < i - w - 1; j++)
{
if (zd[k].a[j] != dfe[j + w + 1])
{
bo = false;
break;
}
}
if (bo)
{
cout << zd[k].b ;
if(i!=dfe.size()-1)
cout<<dfe[i];
break;
}
}
if (!bo)
{
cout << "UNK";
}
w = i;
}
}
return 0;
}