#include <bits/stdc++.h>
using namespace std;
int main()
{
string a[10000],b,c;
int n=0;
while(cin>>a[n])
{
n++;
char x=getchar();
if(x=='\n')break;
}
cin>>b>>c;
for(int i=0;i<n;i++)
{
if(a[i]==b)cout<<c<<" ";
else cout<<a[i]<<" ";
}
return 0;
}