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

int main()
{
    ios_base::sync_with_stdio(false);
    string n;
    char c1, c2;
    cin >> n >> c1 >> c2;
    while (n != "0" || c1 != '0' || c2 != '0') {
        for (int i = 0 ; i < n.size(); ++i) {
            if (n[i] == c1)
                n[i] = c2;
        }
        int j;
        for (j = 0; j < n.size() && n[j] == '0'; ++j);
        cout << n.substr(j, distance(n.begin()+j, n.end())) << "\n";
        cin >> n >> c1 >> c2;
    }
    return 0;
}