package com.demo2;
import java.util.Scanner;
/*
* we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26;
* Give you a letter x and a number y , you should output the result of y+f(x).
*/
public class HDU_oj2055 {
public static void main(String[] args) {
Scanner sn = new Scanner(System.in);
int n = sn.nextInt();
for(int i =0;i < n;i++) {
char c = sn.next().charAt(0); //java中如何输入字符
int num = sn.nextInt();
System.out.println(transfer(c)+num);
}
sn.close();
}
/*
* ASSIC码: a-z 97-122
* A-Z 65-90
*/
public static int transfer(char a) {
if(a >= 'A' && a <= 'Z') {
return (int)a-64;
}else {
return -((int)a-96);
}
}
}