#include <iostream>
#include <string>
using namespace std;
int main()
{
int strwide;
cin >> strwide;
pair< char, char > rotor[][];
pair< char, char > rotor_instead[][];
string input;
int t = ; while( t < )
{
cin >> input;
if ( input.size() == strwide )
{
char start_1 = 'a';
char start_else = 'A';
if ( t == )
{
for ( int m = ; m < input.size(); m++ )
{
rotor[t][m].first = start_1;
rotor[t][m].second = input[m];
start_1 = start_1 + ;
}
}
else
{
for ( int m = ; m < input.size(); m++ )
{
rotor[t][m].first = start_else;
rotor[t][m].second = input[m];
start_else = start_else + ;
}
}
//rotor[t] = input;
t++;
}
} int crypto_number;
cin >> crypto_number;
//string *crypto = new string[crypto_number];
string crypto[];
t = ;
string input_crypto;
while( cin >> input_crypto && input_crypto != "" && t < crypto_number )
{
crypto[t] = input_crypto;
t++;
}
/*for ( int l = 0; l < t; l++ )
{
cout << crypto[l]<< endl;
}*/
//string *crypto_return = new string[crypto_number];
for ( int i = ; i < crypto_number; i++ )
{
for( int a = ; a < ; a++ )
{
for ( int b = ; b < strwide; b++ )
{
rotor_instead[a][b] = rotor[a][b];
}
}
//int second_rotor_count = 0;
//char *crypto_return = new char[crypto[i].size()];
char crypto_return[];
//cout << crypto[i].size() << endl;
for ( int j = ; j < crypto[i].size(); j++ )
{
for ( int r = ; r < strwide; r++ )
{
if ( rotor_instead[][r].second == crypto[i][j])
{
crypto_return[j] = rotor_instead[][r].first; for ( int k = ; k < strwide; k++ )
{
if ( rotor_instead[][k].second == crypto_return[j])
{
crypto_return[j] = rotor_instead[][k].first;
for ( int s = ; s < strwide; s++ )
{
if ( rotor_instead[][s].second == crypto_return[j] )
{
crypto_return[j] = rotor_instead[][s].first;
}
}
} }
} } for ( int d = ; d < strwide; d++ )
{
rotor_instead[][d].first += ;
rotor_instead[][d].second += ;
if (rotor_instead[][d].first == 'a'+ strwide )
{
rotor_instead[][d].first -= strwide;
}
if ( rotor_instead[][d].second == 'A'+strwide )
{
rotor_instead[][d].second -= strwide;
}
} if ( (j+)%strwide == )
{
//second_rotor_count++;
for ( int d = ; d < strwide; d++ )
{
rotor_instead[][d].first += ;
rotor_instead[][d].second += ;
if ( rotor_instead[][d].first == 'A'+strwide )
{
rotor_instead[][d].first -= strwide;
}
if ( rotor_instead[][d].second == 'A'+strwide )
{
rotor_instead[][d].second -= strwide;
}
}
} if ( (j + )%( strwide*strwide) == )
{
for ( int d = ; d < strwide; d++ )
{
rotor_instead[][d].first += ;
rotor_instead[][d].second += ;
if ( rotor_instead[][d].first == 'A'+strwide )
{
rotor_instead[][d].first -= strwide;
}
if ( rotor_instead[][d].second == 'A'+strwide )
{
rotor_instead[][d].second -= strwide;
}
}
} } /*for ( int a = 0; a < 3; a++ )
{
for ( int b = 0; b < strwide; b++ )
{
cout << rotor_instead[a][b].first <<" "<< rotor_instead[a][b].second << endl;
}
}*/
cout << "Enigma "<< i+ <<":"<< endl;
for ( int c = ; c < crypto[i].size(); c++ )
{
cout << crypto_return[c];
}
cout << endl;
if ( i != crypto_number - )
{
cout << endl;
} } return ;
}