THE CODE RUNS FINE FOR TEST CASES..
#include <iostream>
#include <cstdlib>
#include<cctype>
#include<cstring>
using namespace std;
int main ()
{
int t;
char m[26];
char strabc[]="abcdefghijklmnopqrstuvwxyz";
char strABC[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
scanf("%d%s",&t,m);
while(t--)
{
char a[100];
scanf("%s",a);
//cout<<"a= "<<a<<endl;
for(int i=0;i<strlen(a);i++)
{
if(a[i]>=65 &&a[i]<=90)
{
for(int j=0;j<26;j++)
{
if(strABC[j]==a[i])
{ printf("%c",m[j]-96+64);
//cout<<endl<<"m[j]= "<<m[j]<<endl;
//cout<<"j="<<j<<endl;
//cout<<"strABC[j]="<<strABC[j]<<endl;
}
}
}
else if(isalpha(a[i]))
{
for(int j=0;j<26;j++)
{
if(strabc[j]==a[i])
printf("%c",m[j]);
}
}
else if(a[i]=='_')
printf(" ");
else
printf("%c",a[i]);
}
printf("\n");
}
return 0;
}