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-----
Subtask #1 (30 points):

- N = 1

Subtask #2 (70 points):

- Original constraints

-----Example-----
Input:
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

Output:
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.

Difficulty: EASY

Solutions:
t = int(input())
for _ in range(t):
	price = list(map(int, input().split()))
	string = set(input())
	letters = []
	cost = 0
	for i in range(97, 123):
		if chr(i) not in string:
			cost += price[i - 97]
	print(cost)


for t in range(int(input())):
	pl = list(map(int, input().split()))
	al = input()
	for i in al:
		ind = ord(i) - 97
		pl[ind] = i
	s = 0
	for j in pl:
		j = str(j)
		if j.isdigit():
			s += int(j)
	print(s)


t = int(input())
for x in range(t):
	p = list(map(int, input().split()))
	a = input()
	s = 0
	l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	for i in range(len(l)):
		if l[i] not in a:
			s += p[i]
	print(s)


t = int(input())
a = 'abcdefghijklmnopqrstuvwxyz'
for i in range(t):
	c = 0
	p = input().split()
	s = input()
	for j in range(len(a)):
		if a[j] not in s:
			c = c + int(p[j])
	print(c)


for _ in range(int(input())):
	prices = list(map(int, input().split(' ')))
	s = set(input())
	total = 0
	for x in range(97, 123):
		ch = chr(x)
		if ch not in s:
			total += prices[ord(ch) - 97]
	print(total)


try:
	for i in range(int(input())):
		l = list(map(int, input().strip().split()))
		s = input()
		s = list(s)
		alpha = 'abcdefghijklmnopqrstuvwxyz'
		alpha = list(alpha)
		count = 0
		for i in alpha:
			if i not in s:
				count = count + l[ord(i) - 97]
		print(count)
except:
	pass


for i in range(int(input())):
	l = list(map(int, input().split()))
	s = input().lower()
	x = [0] * 26
	for i in s:
		if i.isalpha():
			x[ord(i) - 97] += 1
	sum = 0
	for i in range(26):
		if x[i] == 0:
			sum += l[i]
	print(sum)


for i in range(int(input())):
	t = list(map(int, input().split()))
	n = input()
	s = 'abcdefghijklmnopqrstuvwxyz'
	d = {}
	sum = 0
	for j in n:
		d[j] = d.get(j, 0) + 1
	for j in s:
		if j not in d:
			sum += t[ord(j) - 97]
	print(sum)


t = int(input())
for i in range(t):
	cost = 0
	menu = list(map(int, input().split()))
	word = input()
	for ch in 'abcdefghijklmnopqrstuvwxyz':
		if ch not in word:
			cost = cost + menu[ord(ch) - ord('a')]
	print(cost)


import string
a = string.ascii_lowercase
for _ in range(int(input())):
	d = list(map(int, input().split()))
	s = str(input())
	ans = 0
	for i in range(len(d)):
		if a[i] not in s:
			ans += d[i]
		else:
			pass
	print(ans)


t = int(input())
for _ in range(t):
	prices = list(map(int, input().split()))
	text = input().strip()
	freq = [0] * 26
	for ch in text:
		freq[ord(ch) - ord('a')] += 1
	cost = 0
	for i in range(26):
		if freq[i] == 0:
			cost += prices[i]
	print(cost)


import os, sys, io, math
from re import *
from math import *
from array import *
from heapq import *
from bisect import *
from functools import *
from itertools import *
from statistics import *
from collections import *
I = lambda : [*map(int, sys.stdin.readline().split())]
IP = lambda : map(int, input().split())
IS = lambda : input()
IN = lambda : int(input())
IF = lambda : float(input())
a = [chr(i) for i in range(97, 123)]
for _ in range(IN()):
	(l, s, res) = (I(), IS(), 0)
	for i in range(26):
		if a[i] not in s:
			res += l[i]
	print(res)


for _ in range(int(input())):
	n = list(map(int, input().split()))
	s = input()
	str = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	res = 0
	for i in range(26):
		if str[i] in s:
			continue
		else:
			res += n[i]
	print(res)


for _ in range(int(input())):
	n = list(map(int, input().split()))
	s = input()
	res = 0
	for i in range(26):
		if chr(i + 97) in s:
			pass
		else:
			res += n[i]
	else:
		print(res)


for i in range(int(input())):
	l = list(map(int, input().split()))
	s = input()
	l1 = 'abcdefghijklmnopqrstuvwxyz'
	sum = 0
	for i in range(len(l)):
		if l1[i] not in s:
			sum = sum + l[i]
	print(sum)


import bisect
from collections import Counter
for _ in range(int(input())):
	a = list(map(int, input().split()))
	s = input()
	c = 0
	for i in range(ord('a'), ord('z') + 1):
		if chr(i) not in s:
			c += a[i - 97]
	print(c)


t = int(input())
x = 'abcdefghijklmnopqrstuvwxyz'
for i in range(t):
	a = 0
	b = input().split()
	c = input()
	for j in range(len(x)):
		if x[j] not in c:
			a = a + int(b[j])
	print(a)


for i in range(int(input())):
	a = list(map(int, input().split()))
	x = input()
	tot = 0
	for i in range(ord('a'), ord('z') + 1):
		if chr(i) not in x:
			tot += a[i - 97]
	print(tot)


import string
s = string.ascii_lowercase
for _ in range(int(input())):
	arr = list(map(int, input().split()))
	s1 = input()
	total = 0
	for i in s:
		if i not in s1:
			total += arr[s.index(i)]
			s1 += i
	print(total)


def find_cheapest_pangram(prices, text):
	letters = set(text)
	if len(letters) == 26:
		return 0
	missing_letters = set('abcdefghijklmnopqrstuvwxyz') - letters
	price = sum((prices[ord(letter) - ord('a')] for letter in missing_letters))
	return price
t = int(input())
for _ in range(t):
	prices = list(map(int, input().split()))
	text = input().strip()
	cheapest_price = find_cheapest_pangram(prices, text)
	print(cheapest_price)


t = int(input())
for i in range(t):
	alphabets = 'abcdefghijklmnopqrstuvwxyz'
	a = list(map(int, input().split()))
	s = input()
	c = 0
	for j in alphabets:
		if j not in s:
			c += a[ord(j) - 97]
	print(c)


for _ in range(int(input())):
	cost = list(map(int, input().split()))
	text = input()
	res = 0
	for i in range(26):
		if chr(i + 97) in text:
			pass
		else:
			res += cost[i]
	else:
		print(res)


t = int(input())
for _ in range(t):
	price = list(map(int, input().split()))
	n = input().lower()
	a = [0] * 26
	for i in n:
		if i.isalpha:
			a[ord(i) - 97] += 1
	sum = 0
	for i in range(26):
		if a[i] == 0:
			sum += price[i]
	print(sum)


for i in range(int(input())):
	n = list(map(int, input().split()))
	s = input()
	alphabet = 'abcdefghijklmnopqrstuvwxyz'
	result = 0
	for i in alphabet:
		if i in s:
			continue
		else:
			result += n[alphabet.index(i)]
	print(result)


a = set('abcdefghijklmnopqrstuvwxyz')
for _ in range(int(input())):
	p = list(map(int, input().split()))
	t = input().strip()
	r = set(t)
	m = sorted(list(a - r))
	c = sum((p[ord(k) - ord('a')] for k in m))
	print(c)


for i in range(int(input())):
	a = list(map(int, input().split()))
	x = input()
	t = 0
	for i in range(97, 123):
		if chr(i) not in x:
			t += a[i - 97]
	print(t)


testCase = int(input())
while testCase > 0:
	alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	c = input().split()
	cost = {alp[i]: int(c[i]) for i in range(len(c))}
	s = set(input())
	for i in s:
		alp.remove(i)
	total = 0
	for i in alp:
		total += cost[i]
	print(total)
	testCase -= 1


t = int(input())
n = 'abcdefghijklmnopqrstuvwxyz'
for i in range(t):
	m = 0
	p = input().split()
	q = input()
	for j in range(len(n)):
		if n[j] not in q:
			m = m + int(p[j])
	print(m)


T = int(input())
for t in range(T):
	prices = list(map(int, input().split()))
	text = input().strip()
	alphabet = 'abcdefghijklmnopqrstuvwxyz'
	missing = [ch for ch in alphabet if ch not in text]
	missing_prices = [prices[ord(ch) - ord('a')] for ch in missing]
	total_cost = sum(missing_prices)
	print(total_cost)


for i in range(int(input())):
	l = list(map(int, input().split()))
	s = input()
	s1 = 'abcdefghijklmnopqrstuvwxyz'
	c = 0
	for i in range(26):
		if s1[i] not in s:
			c += l[i]
	print(c)


import string
check = string.ascii_lowercase
for _ in range(int(input())):
	price = 0
	l = list(map(int, input().strip().split()))
	s = str(input())
	s = set(s)
	for i in range(0, len(check)):
		if check[i] not in s:
			price += l[i]
	print(price)


for i in range(int(input())):
	l = list(map(int, input().split()))
	s = str(input())
	for i in s:
		l[ord(i) - 97] = 0
	print(sum(l))


for _ in range(int(input())):
	A = list(map(int, input().split()))
	(s, x) = (list(set(list(input()))), 0)
	for c in s:
		x += A[ord(c) - 97]
	print(sum(A) - x)


T = int(input())
for i in range(T):
	s = input() + ' '
	cost = {}
	present = {}
	spend = 0
	for j in range(26):
		n = s.find(' ')
		cost[97 + j] = int(s[:n])
		present[97 + j] = False
		s = s[n + 1:]
	s = input()
	for k in range(len(s)):
		t = ord(s[k])
		present[t] = True
	for l in range(26):
		if present[97 + l] == False:
			spend += cost[97 + l]
	print(spend)


t = int(input())
for i in range(t):
	arr = list(map(int, input().split()))
	s = input()
	brr = list(map(chr, range(97, 123)))
	count = 0
	for j in range(len(brr)):
		if brr[j] in s:
			continue
		else:
			count += arr[j]
	print(count)