#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int n, c1, c2;
    int k = 0;
    int o = 0;
    int count = 0;
    do
    {
        k = 0;
        o = 0;
        cin >> n >> c1 >> c2;
        if (n >= 0 && n <= 10000 && c1 >= 0 && c1 <= 9 && c2 >= 0 && c2 <= 9)

        while (n != 0)
        {

            if (n % 10 == c1)
                {o = o * 10 + c2;
                k++;
                n /= 10;
                }
            else
            {
                o = o * 10 + n % 10;
                n /= 10;
            }
        }

        while (o != 0)
        {
            n = n * 10 + o % 10;
            o /= 10;
        }
        if (n < 9)
            cout << n * pow(10, k);
        else cout << n;
        count++;

    }while (n && c1 && c2 && count <= 15);

    return 0;
}