#include <iostream>
#include <vector>
using namespace std;
int main() {
string t;
vector<string> s;
while (cin >> t) {
s.push_back(t);
}
string a, b;
b = s.back();
s.pop_back();
a = s.back();
s.pop_back();
//cout << a << ' ' << b << endl;
for (auto &c : s) {
if (c == a)
c = b;
cout << c << ' ';
}
cout << endl;
return 0;
}