#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {

    int N;
    //cin>>N;
    int NR, c1, c2;
    int AUX;
    NR = 1;
    c1 = 1; c2 = 1;
    while (NR != 0 || c1 != 0 || c2 != 0) {
        cin>>NR>>c1>>c2;
        if (NR != 0 || c1 != 0 || c2 != 0) {
        int put = 1;
        while (NR / put != 0) {
            if ((NR /put) % 10 == c1) {
                NR = ((NR/(put*10))*10 + c2) * put + (NR % put);
            }
            //cout<<NR<<" "<<put<<"\n";
            put *= 10;
        }
        cout<<NR<<"\n";
        }

    }
}