#include <bits/stdc++.h>
using namespace std;

int main(){
	string ss[100];
	string s1,s2;
	int i=0;
	while(cin>>ss[i++])
	{
		if(cin.get()=='\n') break;
	}
	cin>>s1>>s2;
	for(int j=0;j<i;j++)
	{
		if(ss[j]==s1) ss[j]=s2;
		cout<<ss[j];
		if(j==i-1) cout<<endl;
		else cout<<" ";
	}
	return 0;
}