#include<bits/stdc++.h>
using namespace std;
// #HR #Strings #Problem
// https://www.hackerrank.com/challenges/designer-pdf-viewer/problem
vector<int> conv(string x){
int n=x.size();
vector<int> ans;
for(int i=0;i<n;i++){
ans.push_back(x[i]-'a'+1)
}
return ans;
}
int designerPdfViewer(vector<int> h, string word) {
vector<int> num=conv(word);
int maxHeight=0;
for(int i=0;i<num.size();i++){
if(maxHeight<h[num[i]-1]){
maxHeight=h[num[i]-1];
}
}
return maxHeight*word.size(); //Area = maxheight*width (each letter has 1 width,so width=n)
}
int main(){
int t;
cin>>t;
while(t--){
vector<int> height(26); //26 alphabet
for(int i=0;i<26;i++){
cin>>height[i];
}
string word;
cin>>word;
cout<<designerPdfViewer(height,word)<<endl;
}
return 0;
}