#include <bits/stdc++.h>

using namespace std;

int c1=1,c2,uc;
int x,v[100000];

int main()
{
    while(cin>>x>>c1>>c2){

        if(c1 == 0 && c2 == 0)
            break;
        int i=1;
        while(x){

            uc=x%10;
            if( uc == c1 )
                uc = c2;
            v[i]=uc;
            x/=10;
            i++;
            }
        for(int j=i-1;j>=1;j--)
            cout<<v[j];


        }





    return 0;
}