#include<stdio.h>
int main()
{
int s;
scanf("%d",&s);
while(s--)
{
int n;
char a;
getchar();
scanf("%c%d",&a,&n);
if(a>='a'&&a<='z')
printf("%d\n",-(a-96)+n);
else
printf("%d\n",a-64+n);
}
return 0;
}
int main()
{
int s;
scanf("%d",&s);
while(s--)
{
int n;
char a;
getchar();
scanf("%c%d",&a,&n);
if(a>='a'&&a<='z')
printf("%d\n",-(a-96)+n);
else
printf("%d\n",a-64+n);
}
return 0;
}