import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String args[]) {
Scanner test = new Scanner(System.in);
int tests = test.nextInt();
for (int bo = 0; bo < tests; bo++) {
Scanner sc = new Scanner(System.in);
int[] integers = new int[26];
int i, sum = 0;
for (i = 0; i < 26; i++) {
integers[i] = sc.nextInt();
}
int sum2 = 0;
for (i = 0; i < 26; i++) {
sum2 += integers[i];
}
Scanner string = new Scanner(System.in);
String sr;
sr = string.nextLine();
char[] charArray = sr.toCharArray();
Arrays.sort(charArray);
String sortedString = new String(charArray);
String srt = "abcdefghijklmnopqrstuvwxyz";
char[] abc = srt.toCharArray();
for (int k = 0; k < charArray.length; k++) {
for (int j = 0; j < 26; j++) {
if (abc[j] == charArray[k]) {
sum = sum + integers[j];
} else {
int p = 0;
}
}
}
int op = sum2 - sum;
System.out.print(op);
}
}
}