// 华为第三题.cpp : 定义控制台应用程序的入口点。
//

include "stdafx.h"

include <iostream>

include <string>

include <vector>

using namespace std;

int main()
{
string input;
string src;
string dest;
cin >> input>>src>>dest;

string mytemp;
int num = 0;
for (int i = 0; i < input.size(); i++)
{
    if (input[i] == src[0])
    {
        num++;
        mytemp.push_back('0');
    }
}
string stard;
for (int i = 0; i < num; i++)
{
    stard.push_back('1');
}
vector<string> res;


for (int i = 0; i < pow(2, num); i++)
{
    string restemp = input;
    int cnt = 0;
    for (int j = 0; j < input.size(); j++)
    {
        if (restemp[j] == src[0])
        {
            if (src[0] > dest[0])
            {
                if (mytemp[cnt] == '1')
                {
                    restemp[j] = dest[0];

                }
            }
            else
            {
                if (mytemp[cnt] == '0')
                {
                    restemp[j] = dest[0];
                }
            }

            cnt++;
        }
    }
    res.push_back(restemp);
    int k = 1;
    int jinwei = 1;
    while (jinwei == 1 && mytemp!=stard)
    {
        if (mytemp[num - k] == '0')
        {
            mytemp[num - k] = '1';
            k++;
            jinwei = 0;
        }
        else if (mytemp[num - k] == '1')
        {
            mytemp[num - k] = '0';
            jinwei = 1;
            k++;
        }
    }
}
for (int i = 0; i < res.size()-1; i++)
{
    cout << res[i] <<',';
}
cout << res[res.size() - 1] << endl;

cin.get();
cin.get();
return 0;

}