#include "iostream"
using namespace std;

int nc1c2()
{
	int n, c1, c2, n2, car, i, j;

	for(i = 0; i < 15; i++)
	{
		cin >> n >> c1 >> c2;

		if( !(n || c1 || c2))
			return 0;
		else 
		{
			n2 = 0;
			j = 0;

			while(n)
			{
				car = n %10;

				if(car == c1)
					n2 += c2 * pow(10, j);
				else
					n2 += car * pow(10, j);

				n = n/10;
				j++;
			}
		}

		cout << n2 << endl;
	}

	return 0;
}

int main()
{
	nc1c2();

	return 0;
}