#include<bits/stdc++.h>
using namespace std;
int main(){
	string str, a, b, tmp;
	char c;
	vector<string> v;
	while(cin>>str){
		c =getchar();
		v.push_back(str);
		if(c == '\n'){
			cin>>a>>b;
			for(int i=0; i<v.size(); i++){
				if(v[i]==a) cout<<b;
				else cout<<v[i];
				if(i!=v.size()-1) cout<<" ";
				else cout<<endl;
			}
			v.clear();
		}
	}
	return 0;
}