#include <iostream>
#include <string.h>

using namespace std;

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

	cin >> s >> c1 >> c2;
	int t = 1;

	while (strcmp (s, "0") != 0 && c1 != '0' && c2 != '0' && t < 15)
	{
		p = strchr (s, c1);

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

		cout << endl << atoi (s);

		cin >> s >> c1 >> c2;
		t++;
	}

	return 0;
}