#include <cstdio>
#include <string.h>
using namespace std;
const int maxn=15,maxl=300;
char key[2][maxn][maxl],str[maxl];
int l[maxn],N;
bool match(char *s,char *k)
{
while (*k)
{
if (*s!=*k)
return false;
++s;
++k;
}
return true;
}
void replace(int cur,int i)
{
char tmp[maxl]= {0};
memcpy(tmp,str,cur);
strcat(tmp,key[1][i]);
strcat(tmp,str+cur+l[i]);
memcpy(str,tmp,sizeof(str));
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("10115.in","r",stdin);
freopen("10115.out","w",stdout);
#endif
while (scanf("%d",&N)&&N!=0)
{
memset(str,0,sizeof(str));
getchar();
for (int i=0; i<N; i++)
{
gets(key[0][i]);
gets(key[1][i]);
l[i]=strlen(key[0][i]);
}
gets(str);
for (int i=0; i<N; i++)
for (int j=0; str[j+l[i]-1]; j++)
if (match(str+j,key[0][i]))
{
replace(j,i);
j=0;
}
puts(str);
}
fclose(stdin);
fclose(stdout);
return 0;
}