#include<stdio.h>
#include<cstring>
#include<stdlib.h>
using namespace std;
char s[100];
int c1, c2, i, ls, g;
int main()
{
    while(1)
    {
        scanf("%s %d %d ", s, &c1, &c2);
        if(s[0] == '0' && s[1] == 0 && c1 == 0 && c2 == 0)
            break;
            for (int i = 0 ; i < strlen(s) ; i++)
                if(s[i] == c1-'0')
                   s[i] = c2+'0';
            printf("%d\n", atoi(s));
        }
    return 0;
}