include<iostream>
include <stdio.h>
include <map>
include <string>
include <cstring>
include <cctype>
using namespace std;
int main()
{
map<string, string>map;
string a, b; cin >> a;
while (cin>>a && a != "END")
{
cin>>b;
map[b] = a;
}
cin >> a;
string c; string z, yu = ""; getline(cin, c);
while (getline(cin,c) && c != "END")
{
for (int i = 0; i < c.size(); i++)
{
if (islower(c[i]))
{
z += c[i];
}
else
{
if (map[z] != "")cout << map[z];
else cout << z;
cout << c[i]; z = "";
}
}
cout << endl;
}
}