#include <string>
#include <iostream>

using namespace std;

int string_to_int(string s){
	int x = 0;
	for(int i=0; i<(int)s.size(); i++){
		x = 10*x+(s[i]-48);
	}
	return x;	
}


int main(){
	string s;
	char c1, c2;
	
	while(1){
		cin>>s>>c1>>c2;
		if(c1 == c2){
			if(c1 == '0' && s.compare("0") == 0){
				return 0;
			}
			else{
				cout<<s<<endl;
			}
			continue;
		}
		for(int i=0; i<(int)s.size(); i++){
			if(s[i] == c1){
				s[i] = c2;
			}
		}
		cout<<string_to_int(s)<<endl;
	}
	return 0;
}