#include<iostream>
#include<string>
using namespace std;
int main()
{
int arr[3];
string order[3];
for (int a = 0; a < 3; a++)
{
cin >> arr[a];
}
for (int o = 0; o < 3; o++)
{
cin >> order[o];
}
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2 - i; j++)
{
if (arr[j] >= arr[j + 1])
{
int temp = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = temp;
}
}
}
for (int q = 0; q < 3; q++)
{
if (order[q] == "A")
{
cout << arr[0] << " ";
}
if (order[q] == "B")
{
cout << arr[1] << " ";
}
if (order[q] == "C")
{
cout << arr[2] << " ";
}
}
system("pause");
return 0;
}