#include <iostream>
#include<string.h>
using namespace std;
int f(char c){
int res;
if (c >= 'a'&&c <= 'z')
res = -(c - 'a' + 1);
else if (c >= 'A'&&c <= 'Z')
res = c - 'A' + 1;
return res;
}
int main()
{
int n;
char c;
int a;
while (cin >> n)
{
while (n--)
{
cin >> c >> a;
cout<<f(c) + a<<endl;
}
}
return 0;
}
#include<string.h>
using namespace std;
int f(char c){
int res;
if (c >= 'a'&&c <= 'z')
res = -(c - 'a' + 1);
else if (c >= 'A'&&c <= 'Z')
res = c - 'A' + 1;
return res;
}
int main()
{
int n;
char c;
int a;
while (cin >> n)
{
while (n--)
{
cin >> c >> a;
cout<<f(c) + a<<endl;
}
}
return 0;
}