#define _CRT_SECURE_NO_DEPRECATE

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

string s;
char c1, c2;

int main(){
	int i, ok;

	//freopen("test.in", "r", stdin);
	//freopen("test.out", "w", stdout);

	cin >> s >> c1 >> c2;

	while (s[0] != '0' || c1 != '0' || c2 != '0'){
		ok = 1;
		for (i = 0; i < s.size(); i++){
			if (ok){
				if (s[i] != '0'){
					if (s[i] == c1) s[i] = c2;
					ok = 0;
				}
			}
			else{
				if (s[i] == c1) s[i] = c2;
			}
		}

		cout << atoi(s.c_str()) << '\n';

		cin >> s >> c1 >> c2;
	}

	return 0;
}