#include <fstream>
#include <iostream>
#include <cstring>
#include <vector>

#define f cin
#define g cout

using namespace std;

char s[10];

int c1 , c2 , i , n , x ;
vector <int> a;

int main()
{
    //ifstream f("nc1c2.in");
    //ofstream g("nc1c2.out");

    f >> s >> c1 >> c2;

    while (strcmp(s , "0") != 0 || c1 != 0 || c2 != 0)
    {
        n = strlen(s); x =0;
        for (i = 0; i < n; ++i)
         if (s[i] == c1 + '0') x = x * 10 + c2;
         else x = x * 10 + s[i] - '0';

        a.push_back(x);

        f >> s >> c1 >> c2;

    }

    for (i = 0; i < a.size(); ++i)
     g << a[i] << "\n";

    return 0;
}