#include<bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
char map[26],s[100];
int t,n,i;
cin>>t>>map;
while(t–)
{
cin>>s;
for(i=0;s[i];i++)
{
if(islower(s[i]))
s[i]=map[s[i]-'a'];
if(isupper(s[i]))
s[i]=map[s[i]-'A'];
if(s[i]=='_')
s[i]='';
}
cout<<s<<endl;
}
return 0;
}