#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>

#define maxn 1010

using namespace std;

ifstream fin("test.in");
ofstream fout("test.out");

string f,s;
char b[256];
vector<int> type;
vector<string> ss;

string convert_int(string s)
{
    int x = 0;

    for (int i = 0; i < s.length(); ++i)
    {
        x = x*10 + s[i] - '0';
    }

    string ns;

    while (x != 0)
    {
        int c = x % 16;
        if (c < 10)
            ns += (char)(c+'0');
        else ns += (char)(c-10+'A');

        x /= 16;
    }

    return ns;
}

int to_dig(char x)
{
    if ('0' <= x && x <= '9')
        return x - '0';
    else return x -'A'+10;
}

string convert_hexa(string s)
{
    int x = 0;

    for (int i = 0; i < s.length(); ++i)
    {
        x = x*16 + to_dig(s[i]);
    }

    string ns;

    while (x != 0)
    {
        int c = x % 16;
        if (c < 10)
            ns += (char)(c+'0');
        else ns += (char)(c-10+'A');

        x /= 16;
    }

    return ns;
}

char to_char (int x)
{
    if (x <= 9)
        return x + '0';
    else return x - 10 + 'A';
}

string convert_string(string s)
{
    string ns;

    for (int i = 0; i < s.length(); ++i)
    {
        int x = s[i];
        ns += to_char(x/16);
        ns += to_char(x%16);
    }

    return ns;
}

string convert_char(string s)
{
    string ns;

    int x = s[0];
    ns += to_char(x/16);
    ns += to_char(x%16);

    return ns;
}

void put(int i, int p)
{
    if (type[i] == 0)
    {
        string s = convert_int(ss[i]);

        for (int i = 0; i < s.length(); ++i)
        {
            b[i+p] = s[i];
        }

        for (int i = 0; i+1 < s.length(); i += 2)
        {
            swap(b[i+p],b[i+p+1]);
        }
    }
    else if (type[i] == 1)
    {
         string s = convert_hexa(ss[i]);

        for (int i = 0; i < s.length(); ++i)
        {
            b[i+p] = s[i];
        }

        for (int i = 0; i+1 < s.length(); i += 2)
        {
            swap(b[i+p],b[i+p+1]);
        }
    }
    else if (type[i] == 2)
    {
        string s = convert_string(ss[i]);

        for (int i = 0; i < s.length(); ++i)
        {
            b[i+p] = s[i];
        }
    }
     else
    {
        string s = convert_char(ss[i]);

        for (int i = 0; i < s.length(); ++i)
        {
            b[i+p] = s[i];
        }
    }
}

int main()
{

    getline(cin,f);
    getline(cin,s);

    int i = 0, j = 0;

    for (i = 0; i < f.length() && j < s.length(); ++i)
    {
        if (f[i] == ' ')
        {
            while (j < s.length() && s[j] == ' ')
                ++j;
        }
        else if (f[i] == '%')
        {
            ++i;
            if (f[i] == 'u')
            {
                string m;
                type.push_back(0);

                while ('0' <= s[j] && s[j] <= '9')
                {
                    m += s[j];
                    ++j;
                }

                ss.push_back(m);
            }
            else if (f[i] == 'x')
            {
                string m;
                type.push_back(1);

                j += 2;

                while ('0' <= s[j] && s[j] <= '9' || 'A' <= s[j] && s[j] <= 'F')
                {
                    m += s[j];
                    ++j;
                }

                ss.push_back(m);
            }
            else if (f[i] == 's')
            {
                string m;
                type.push_back(2);

                while (s[j] != ' ')
                {
                    m += s[j];
                    ++j;
                }

                ss.push_back(m);
            }
            else
            {
                string m;
                m += s[j];
                ++j;

                type.push_back(3);
                ss.push_back(m);
            }
        }
        else
        {
            ++j;
        }
    }

    for (int k = 0; k < type.size(); ++k)
    {
        int x = 0;

        while (f[i] == ',')
        {
            ++i;
        }

        while (i < f.length() && f[i] != ',')
        {
            x = x*10 + f[i] -'0';
            ++i;
        }

        x *= 2;

        put(k,x);
    }

    for (int i = 0; i < 256; ++i)
    {
        if (b[i] == 0)
        {
            cout << '0';
        }
        else cout << b[i];
    }
}