#include 

using namespace std;

bool v[8];
int main()
{
    int j,i;
    bool ok;
    for( j = 0; j < 5; j++)
    {
        ok = 1;
        int nr;
        short qw = 1;
        cin >> hex >> nr;
        while(nr!=0)
        {
            v[8-qw] = v[8-qw]+(nr%2);
            qw++;
            nr=nr/2;
        }
        if(v[0] && v[1] && v[2] && v[3])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "B";
            v[0] = 0;
            v[1] = 0;
            v[2] = 0;
            v[3] = 0;
        }
        if(v[4] && v[5] && v[6] && v[7])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "~B";
            v[4] = 0;
            v[5] = 0;
            v[6] = 0;
            v[7] = 0;
        }
        if(v[0] && v[1] && v[4] && v[5])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "A";
            v[0] = 0;
            v[1] = 0;
            v[4] = 0;
            v[5] = 0;
        }
        if(v[1] && v[2] && v[5] && v[6])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "C";
            v[1] = 0;
            v[2] = 0;
            v[5] = 0;
            v[6] = 0;
        }
        if(v[2] && v[3] && v[6] && v[7])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "~A";
            v[2] = 0;
            v[3] = 0;
            v[6] = 0;
            v[7] = 0;
        }
        if(v[0] && v[3] && v[4] && v[7])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "~C";
            v[0] = 0;
            v[3] = 0;
            v[4] = 0;
            v[7] = 0;
        }
        if(v[0] && v[1])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "AB";
            v[0] = 0;
            v[1] = 0;
        }
        if(v[1] && v[2])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "BC";
            v[1] = 0;
            v[2] = 0;
        }
        if(v[2] && v[3])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "~AB";
            v[2] = 0;
            v[3] = 0;
        }
        if(v[4] && v[5])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "A~B";
            v[4] = 0;
            v[5] = 0;
        }
        if(v[5] && v[6])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "~BC";
            v[5] = 0;
            v[6] = 0;
        }
        if(v[6] && v[7])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "~A~B";
            v[6] = 0;
            v[7] = 0;
        }
        if(v[0] && v[4])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "A~C";
            v[0] = 0;
            v[4] = 0;
        }
        if(v[1] && v[5])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "AC";
            v[1] = 0;
            v[5] = 0;
        }
        if(v[2] && v[6])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "~AC";
            v[2] = 0;
            v[6] = 0;
        }
        if(v[7] && v[4])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "~B~C";
            v[7] = 0;
            v[4] = 0;
        }
        if(v[3] && v[7])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "~A~C";
            v[3] = 0;
            v[7] = 0;
        }
        if(v[3] && v[0])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "B~C";
            v[3] = 0;
            v[0] = 0;
        }
        if(v[7] && v[4])
        {
            if(!ok)
                cout << " + ";
            else ok = 0;
            cout << "~B~C";
            v[7] = 0;
            v[4] = 0;
        }
        for(i = 0; i < 8; i++)
        {
            if(v[i]!=0)
            {
                if(!ok)
                    cout << " + ";
                else ok = 0;
                if(i % 4 == 2 || i % 4 == 3)
                    cout << "~";
                cout << "A";
                if(i > 3)
                    cout << "~";
                cout << "B";
                if(i % 4 == 0 || i % 4 == 3)
                    cout << "~";
                cout << "C";
            }
        }
        cout << '\n';
    }
    return 0;
}