#include <iostream>
#include <cstring>
#include <fstream>

using namespace std;

char s[15][160];
char print[150];
int n;
int main()
{
    char c;
    int i,j,k,poz;
    cin>>n;cin.get(c);

    for(i=1;i<=n;i++)
       cin.getline(s[i],150);
   cin.getline(print,150);
    i=0;
    while(print[i]!=',' && i<strlen(print)) i++;
     j=i+1;
     int lg=j;
    for(i=0;i<lg-1;)
    {
        if(print[i]=='%')
        {
            for(int k=1;k<=n;k++)
                if(s[k][0]==print[j])
                    {poz=k;
                    break;}
            if(print[i+1]=='s')
            {
                for(k=2;k<strlen(s[poz]);k++) cout<<s[poz][k];
                i+=2;
            }
            else if(print[i+1]=='.')
            {
                for(int k=1;k<=n;k++)
                if(s[k][0]==print[j])
                    {poz=k;
                    break;}
                k=2;
                while(s[poz][k]!='.') {cout<<s[poz][k]-'0';k++;}
                cout<<'.';
                k++;
                int x=print[i+2]-'0';
                while(x>1 && k< strlen(s[poz])) {cout<<s[poz][k]-'0';k++;x--;}
                if(k==strlen(s[poz]) && x>0)
                    while(x>0) {cout<<0;x--;}
                if(x==1)
                {
                    if (k+1<strlen(s[poz])){
                     if(s[poz][k+1]>=5) cout<<(s[poz][k]-'0')+1;
                     else ;
                    }
                    else
                    {
                         if(s[poz][k]<5) cout<<(s[poz][k]-'0')+1;
                        else;                }
                }
               i+=4;
            } else
            {
                for(int k=1;k<=n;k++)
                if(s[k][0]==print[j])
                    {poz=k;
                    break;}
                int lung=strlen(s[poz])-2;
                int x= print[i+1]-'0';
                while(x>lung) {cout<<" ";x--;}
                for(k=2;k<strlen(s[poz]);k++) cout<<s[poz][k]-'0';
                i+=3;
            }
            j+=2;
        }
        else {cout<<print[i]; i++;}
    }

}