#include <cstring>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

ifstream f("date.in");
//#define f cin

int n;
char s[15][105];
int ptr[256];
char str[105];
queue<char> q;

int main()
{
    f >> n;
    for (int i = 1; i <= n; i++) {
        f >> s[i];
        ptr[s[i][0]] = i;
    }
    f.get();
    f.getline(str, 104);

    for (int i = 0; i < strlen(str); i++) {
        if (str[i] == ',') {
            q.push(str[i + 1]);
        }
    }

    for (int i = 0; i < strlen(str) && str[i] != ','; i++) {
        if (str[i] == '%') {
            if (str[i + 1] == 's') {
                char lit = q.front();
                q.pop();

                int p = ptr[lit];
                cout << (s[p] + 2);

                i++;
            }
            if (str[i + 1] == '.') {
                int nr = 0;
                while ((str[i] < '0' || '9' < str[i]) && i < strlen(str) && str[i] != ',') {
                    i++;
                }
                while ('0' <= str[i] && str[i] <= '9' && i < strlen(str) && str[i] != ',') {
                    nr = nr * 10 + str[i] - '0';
                    i++;
                }

                char lit = q.front();
                q.pop();

                int p = ptr[lit], j;
                for (j = 2; s[p][j] != '.'; j++) {
                    cout << s[p][j];
                }
                cout << '.'; j++;
                while (nr > 1) {
                    cout << s[p][j];
                    nr--; j++;
                }
                if (isdigit(s[p][j]) && isdigit(s[p][j + 1])) {
                    int num = (s[p][j] - '0') * 10 + s[p][j + 1] - '0';
                    cout << (num + 5) / 10;
                    nr--;
                }
                while (nr) {
                    nr--;
                    cout << '0';
                }
            }
            if (isdigit(str[i + 1])) {
                char lit = q.front();
                q.pop();

                int p = ptr[lit];

                int nr = 0;
                while ((str[i] < '0' || '9' < str[i]) && i < strlen(str) && str[i] != ',') {
                    i++;
                }
                while ('0' <= str[i] && str[i] <= '9' && i < strlen(str) && str[i] != ',') {
                    nr = nr * 10 + str[i] - '0';
                    i++;
                }

                int sz = strlen(s[p] + 2);
                while (sz < nr) {
                    nr--;
                    cout << ' ';
                }
                cout << (s[p] + 2);
            }
        } else {
            cout << str[i];
        }
    }
    cout << '\n';

    return 0;
}