#include <iostream>
#include <fstream>
using namespace std;
//ifstream in("nc1c2.in");
//ofstream out("nc1c2.out");
int nrcif(int x)
{
    if(x==0)
        return 1;
    int nrcf=0;
    while(x)
    {
        nrcf++;
        x=x/10;
    }
    return nrcf;
}
int main()
{
    int x,c1,c2;
    cin>>x>>c1>>c2;
    while(x!=0 || c1!=0 || c2!=0)
    {
        int poz=nrcif(x);
        int cpoz=poz;
        int v[poz+1];
        while(x)
        {
            v[poz]=x%10;
            x=x/10;
            poz--;
        }
        poz=cpoz;
        int i=1;
        while(i<=poz)
        {
            if(v[i]==c1)
                v[i]=c2;
            i++;
        }
        i=1;
        while(v[i]==0 && i<=poz)
            i++;
        if(i==poz+1)
            cout<<0<<"\n";
        else
        {
            while(i<=poz)
            {
                cout<<v[i];
                i++;
            }
            cout<<"\n";
        }
        cin>>x>>c1>>c2;
    }
    return 0;
}