#include<cstdio> #include<fstream> #include<iostream> #include<iomanip> #include<algorithm> #include<vector> #include<bitset> #include<deque> #include<queue> #include<set> #include<map> #include<cmath> #include<cstring> #include<ctime> #include<cstdlib> #include<unordered_map> #define ll long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define pll pair<ll,ll> #define all(x) (x).begin(), (x).end() #define fi first #define se second using namespace std; int i, n, nr; char c1, c2; string s; int main() { cin.sync_with_stdio(false); // freopen("test.in", "r", stdin); // freopen("test.out", "w", stdout); for(;;) { cin >> s >> c1 >> c2; if(s[0] == '0' && c1 == '0' && c2 == '0') break; n = s.size(); for(i = 0; i < n; i++) if(s[i] == c1) s[i] = c2; nr = 0; for(i = 0; i < n; i++) nr = nr * 10 + s[i] - '0'; cout << nr << '\n'; } return 0; }