#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string a, b;
map<string, string> m;
string str;
cin >> n;
while (n--)
{
cin >> a >> b;
m[a] = b;
}
cin >> str;
str += " ";
string s = "";
for (int i = 0; str[i]; i++)
{
if (str[i] >= 'a' && str[i] <= 'z')
{
s += str[i];
}
else
{
if (m.count(s))
cout << m[s];
else if (s != "")
cout << "UNK";
cout << str[i];
s = "";
}
}
return 0;
}