#include <iostream>

using namespace std;

int main()
{
	char s[6], c1, c2, *p;

	cin.getline(s, 6);
	cin >> c1 >> c2;


	while (strcmp (s, "0"))
	{
		p = strchr (s, c1);

		while (p)
		{
			s[p-s] = c2;
			p = strchr (s, c1);
		}

		cout << atoi (s) << endl;

		cin.get();
		cin.getline(s, 6);
		cin >> c1 >> c2;
	}

	return 0;
}