#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
//FILE* fin=freopen("date.in","r",stdin);
//FILE* fout=freopen("date.out","w",stdout);
int n,lg;
char nr[20],c1,c2;
int main()
{
    int i;
    //scanf("\n");
    //scanf("%s %c %c",nr,&c1,&c2);
    while (1==1)
    {
        scanf("%s %c %c",nr,&c1,&c2);
        if (nr[0]=='0' && c1=='0' && c2=='0') exit(0);
        lg=strlen(nr);
        for (i=0; i<lg; i++)
        {
            if (nr[i]==c1) nr[i]=c2;
        }
        i=0;
        while (nr[i]=='0') i++;
        if (nr[i]!=0)
        printf("%s\n",nr+i);
        else printf("0");
        nr[0]=0;
    }
    return 0;
}