#include <iostream>
#include <string>

using namespace std;

int f, p;
string n;
char c1, c2;

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