#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    char n[6];
    char c1, c2;
    int i;

    bool run = true;
    while(run)
    {
        cin >> n >> c1 >> c2;
        if(!strcmp(n, "0") && c1 == '0' && c2 == '0')
        {
            return 0;
        }
        else
        {
            for(i=0; i<strlen(n); i++)
                if(n[i] == c1)
                    n[i] = c2;
            i=0;
            while(n[i] == '0')
                i++;
            cout << n+i << '\n';
        }
    }
    return 0;
}