#include<iostream>
#include<cstdio>
#include<map>
#include<string>
#include<cstring>
using namespace std;
const int SIZE=10000+16;
char book[SIZE];
map<string, string> dic;
void fun_in()
{
char start[6]={'\0'};
scanf("%s",start);
getchar();
string y;
while(cin>>y&&y.compare("END"))
{
string x;
cin>>x;
dic[x]=y;
}
}
bool letter(char a)
{
if('a'<=a&&a<='z')
return true;
return false;
}
void fun_out()
{
char start[6]={'\0'};
scanf("%s",start);
getchar();
while(gets(book)&&strcmp(book,"END")!=0)
{
int r=0;
while(book[r])
{
char lett[SIZE]={'\0'};
int l=0;
while(letter(book[r])&&book[r])
{
lett[l++]=book[r++];
}
string k=lett;
if(dic.find(k)!=dic.end())
{
cout<<dic[k];
}
else
{
cout<<lett;
}
char fu[SIZE]={'\0'};
l=0;
while(!letter(book[r])&&book[r])
{
fu[l++]=book[r++];
}
k=fu;
if(dic.find(k)!=dic.end())
{
cout<<dic[k];
}
else
{
cout<<fu;
}
}
printf("\n");
}
}
int main()
{
fun_in();
fun_out();
return 0;
}