#include <stdio.h>

long replace(long n, int c1, int c2)
{
    int cifre[100];

    int count;

    while(n != 0)
    {
        cifre[count++] = n % 10;
        n /= 10;
    }

    int i;
    for(i = 0; i < count; i++)
        if(cifre[i] == c1)
            cifre[i] = c2;

    for(i = count - 1; i >= 0; i--)
        n = n * 10 + cifre[i];

    return n;
}

int main(void)
{
    long n;
    int c1, c2;
    do{

    scanf("%ld", &n);
    scanf("%d", &c1);
    scanf("%d", &c2);
     printf("%ld\n", replace(n, c1, c2));
    }while(!(( n == 0) && (c1 == 0) && (c2 == 0)));

    return 0;

}