#include <iostream>
#include <string> using namespace std; bool islower(char ch)
{
if (ch >= 'a' && ch <= 'z')
return true;
return false;
} bool isUpper(char ch)
{
if (ch >= 'A' && ch <= 'Z')
return true;
return false;
}
int main()
{
int T;
char ch;
int y, sum = ;
cin >> T;
while (T--)
{ cin >> ch >> y;
sum = y;
if (islower(ch))
{
sum = sum - ( ch - 'a'+ );
}
else
{
sum = sum + (ch - 'A' + );
}
cout << sum << endl; }
return ;
}