#include<fstream>
#include<iostream>
#include<string.h>
using namespace std;
ifstream fin("comis.in");
ofstream fout("comis.out");

char n[100009];
int i, j;
char c1, c2;

int main(){
    int ok = 1;
    while (ok){
        cin >> n >> c1 >> c2;
        if (n[0] == '0' and c1 == '0' and c2 == '0')
            ok = 0;
        else {
            for (i = 0; i < strlen(n); i++)
                if (n[i] == c1)
                    n[i] = c2;
            i = 0;
            while (n[i] == '0')
                i++;
            for (j = i; j < strlen(n); j++)
                cout << n[j];
            cout <<'\n';
        }
    }
}