#include <cstdio>

using namespace std;

#define BSIZE 65536

int p,t,i,c1,c2;
char str[BSIZE];
char buffer[BSIZE];

int main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif

fread(buffer,1,BSIZE,stdin);

t=0;

while (true)
{
    str[0]=0;
    while ('0'<=buffer[t] && buffer[t]<='9')
    {
        str[++str[0]]=buffer[t];
        ++t;
    }

    if (str[0]==0) return 0;

    if (buffer[t]=='\r') return 0;

    ++t;
    c1=buffer[t]-'0';

    ++t;
    if (buffer[t]=='\r') return 0;

    ++t;
    c2=buffer[t]-'0';
    ++t;

    if (buffer[t]=='\r') return 0;
    ++t;

    for (i=1;i<=str[0];++i)
    if (str[i]-'0'==c1) str[i]=c2+'0';

    i=1;
    while (str[i]=='0') ++i;

    if (i>str[0]) continue;

    for (;i<=str[0];++i)
    printf("%c",str[i]);

    printf("\n");
}

return 0;
}