#include <map>
#include <string.h>
#include <iostream>
using namespace std;
#include<stdio.h>
int main()
{
char s1[20],s2[20],s[3005],s3[20],c,a[100];
int k=0,i,j;
map<string,string>v;
cin>>s;
while(cin>>s1)
{
if(strcmp(s1,"END")==0)break;
cin>>s2;
v[s2]=s1;
}
getchar();
while(gets(s))
{
if(strcmp(s,"START")==0)continue;
if(strcmp(s,"END")==0)break;
for(i=0;s[i]!=0;i++)
{
if(islower(s[i]))
a[k++]=s[i];
else
{ a[k]=' ';
if(v.count(a))
cout<<v[a];
else cout<<a;
cout<<s[i];
for(j=0;j<k;j++)
a[j]=' ';
k=0;
}
}
cout<<endl;
}
return 0;
}