Girdhari sir is very passionate about his subject and he also likes to give his students some puzzles. Today he gave his students a simple Mental ability question to solve.
Consider string S which is made of all lower case alphabets(all letters come only once and |S|=26.
S = "abcdefghijklmnopqrstuvwxyz", Then he gave his students another String T. Students had to calculate the power of string T.
Power of string T is the total sum of value of opposite aplhabets than occur in String S.
(In current String S , "z" is opposite of "a" and vice-versa. Similarly "y" is opposite of "b" and vice-versa , "x" opposite of "c" and list goes on.)
(Value of a=1,b=2,c=3......z=26. These values stay same and does not change)
Girdhari sir felt that the question was too simple so he decided to give Students a permutation of S.
You have to calculate the power of String T with the help of String S.
Input Format:
First Line Conatins X the No of Test Cases
Each Test Case have a String S (a Permutation of 26 Lower Case Alphabets),Follwed by N the Length of String T in next Line
and After that String T in next Line.
Output Format:
X Lines each Containing the power of String T for Each Test Case
Constraints:
X (No of test cases): 2<=X<=1000
|S|=26
N (length of string T): 3<=N<=100
In case 1:
According to string S , “a” is opposite of “z” and vice versa ,
Similarly “b” and “y” are opposite
Similarly “c” and “x” are opposite
So, Power of string T will be
oppositeof(a) + oppositeof(b) + oppositeof(c) = Valueof(z) + Valueof(y) + Valueof(x) respectively
26 + 25 + 24 = 75
(Remember value of alphabets does not change only their opposite character is changing.
Value of “a” will always remain 1 , similarly value of “b” will always be 2 and so on.)
In case 2:
According to string S , “z” is opposite of “a” and vice versa ,
Similarly “y” and “b” are opposite
Similarly “x” and “c” are opposite
Similarly “w” and “d” are opposite
So, Power of string T will be
oppositeof(z) + oppositeof(y) + oppositeof(x) + oppositeof(w) = Valueof(a) + Valueof(b) + Valueof(c) + Valueof(d)respectively
1 + 2 + 3 + 4 = 10