# Mathison and pangrams: MATPAN

### Read problems statements in mandarin chinese, russian and vietnamese as well.

Mathison recently inherited an ancient papyrus that contained some text. Unfortunately, the text was not a PANGRAM. Now, Mathison has a particular liking for holoalphabetic strings and the text bothers him. The good news is that Mathison can buy letters from the local store in order to turn his text into a pangram.

However, each letter has a price and Mathison is not very rich. Can you help Mathison find the cheapest way to obtain a pangram?

### Input

The first line of the input file will contain one integer, T, representing the number of tests.

Each test will be formed from two lines. The first one contains 26 space-separated integers, representing the prices of all letters. The second will contain Mathison’s initial text (a string of N lowercase letters).

### Output

The output file will contain T lines, one for each test. Each line will contain the answer for the corresponding test.

### Constraints and notes

• 1 ≤ T ≤ 10
• 1 ≤ N ≤ 50,000
• All prices are natural numbers between 1 and 1,000,000 (i.e. 106).
• A pangram is a string that contains every letter of the Latin alphabet at least once.
• All purchased letters are added to the end of the string.

### Subtaks

• N = 1

• Original constraints

### Sample Input 1

``````2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
abcdefghijklmopqrstuvwz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
thequickbrownfoxjumpsoverthelazydog
``````

### Sample Output 1

``````63
0
``````

### Explanation

```First test
There are three letters missing from the original string: n (price 14), x (price 24), and y (price 25).
Therefore the answer is 14 + 24 + 25 = 63.

Second test
No letter is missing so there is no point in buying something. The answer is 0.
```

## Mathison and pangrams Codechef solution in C

``````#include &lt;stdio.h>
#include &lt;string.h>

int main(void) {
int t,n,cost&#91;26];
char str&#91;50001];
scanf("%d",&amp;t);
int arr&#91;26];
int sum;
while(t--)
{
sum = 0;
for(int i=0;i&lt;26;i++)
scanf("%d",&amp;cost&#91;i]);
scanf("%s",str);
n = strlen(str);
for(int i=0;i&lt;26;i++)
{
arr&#91;i] = 0;
}
for(int i=0;i&lt;n;i++)
{
arr&#91;str&#91;i] - 'a']++;
}
for(int i=0;i&lt;26;i++)
{
if(arr&#91;i] == 0)
sum += cost&#91;i];
}
printf("%d\n",sum);
}
return 0;
}``````

## Mathison and pangrams Codechef solutionin C++ 14

``````#include &lt;bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
int arr&#91;26];
int a=0,cost=0;
for(int i=0;i&lt;26; i++){
cin>>arr&#91;i];
}
string s;
cin>>s;
for(int i='a'; i&lt;='z'; i++){
bool  b=true;
for(int j=0; j&lt;s.size(); j++){
if(i==s&#91;j]){
b=false;
break;
}
}
if(b) cost+=arr&#91;a];
a++;
}
cout&lt;&lt;cost;
cout&lt;&lt;endl;
}
return 0;
}``````

## Mathison and pangrams Codechef solution in Python 3

``````t=int(input())
for i in range(t):
cost=0
word=input()

for ch in "abcdefghijklmnopqrstuvwxyz":
if ch not in word:
print(cost)
``````

## Mathison and pangrams Codechef solution in Java

``````/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scn = new Scanner(System.in);
int t=scn.nextInt();
int cost[]=new int;
int h[]=new int;
String s;
while(t-->0) {
for(int i=0;i < 26;i++) {
cost[i]=scn.nextInt();
h[i]=0;
}
s=scn.next();
for(int i=0;i < s.length();i++)
h[s.charAt(i)-'a']++;
int ans=0;
for(int i=0;i < 26;i++) {
if(h[i]==0)
ans+=cost[i];
}
System.out.println(ans);
}
}
}``````