#include<iostream>
#include<cmath>
using namespace std;
int n,c1,c2,c;
void oglindeste(int &n)
{
    int og=0;
    while(n)
    {
        og=og*10+n%10;
        n/=10;
    }
    n=og;
}
void schimba(int &n,int c1,int c2)
{
    int x=n;
    n=0;
    while(x)
    {
        if(x%10==c1)
            n=n*10+c2;
        else
            n=n*10+x%10;
            x/=10;
    }
oglindeste(n);
}
int main()
{
    do{
        cin>>n>>c1>>c2;
        c++;
        if(!(n==0 && c1==0 && c2==0) && c1>=0 &&c1<=9 && c2>=0 &&c2<=9 && n>=0 && n<=(int)pow(10,5))
            {schimba(n,c1,c2);
            if(n>=0 &&n<=(int)pow(10,5))
            cout<<n<<endl;}
    }while(!(n==0 && c1==0 && c2==0) && c!=15);
    return 0;
}