#include<bits/stdc++.h>
using namespace std;
int main(){
int x[3];
cin>>x[0]>>x[1]>>x[2];
sort(x,x+3);
char y[3];
cin>>y;
if(y[0]=='A'){
cout<<x[0]<<" ";
if (y[1]=='B'){
cout<<x[1]<<" "<<x[2];
}else{
cout<<x[2]<<" "<<x[1];
}
}else if(y[0]=='B'){
cout<<x[1]<<" ";
if (y[1]=='A'){
cout<<x[0]<<" "<<x[2];
}else{
cout<<x[2]<<" "<<x[0];
}
}else{
cout<<x[2]<<" ";
if (y[1]=='A'){
cout<<x[0]<<" "<<x[2];
}else{
cout<<x[2]<<" "<<x[0];
}
}
return 0;
}