#include <iostream>
#include <string>

using namespace std;

char c1, c2;
string n;

int main()
{
    while(1){
        cin >> n >> c1 >> c2;
        if((n=="0") && (c1=='0') && (c2=='0'))
            return 0;
        else
            for(int i=0; i<n.length(); i++)
                if(n[i]==c1)
                    n[i]=c2;
        cout << n;
    };
    return 0;
}