#include <iostream>
#include <string>
using namespace std ;
string str[200] ;
string str1 , str2 ;
int main () {
int i = 0 ;
while ( cin >> str[i] ) {
i ++ ;
if ( cin.get() == '\n' ) break ;
}
cin >> str1 >> str2 ;
for ( int j = 0 ; j < i ; j ++ ) {
if ( str[j] == str1 ) str[j] = str2 ;
}
for ( int j = 0 ; j < i ; j ++ ) {
cout << str[j] <<' ' ;
}
return 0 ;
}