P19615 [HackerEarth] Chotu is a student of IIIT-A and as its a tradition here he wants to copy his assignment on the last day, but to his horror it was a very long Code. His best friend Motu comes to his res
普及-
题目描述

Chotu is a student of IIIT-A and as its a tradition here he wants to copy his assignment on the last day, but to his horror it was a very long Code. His best friend Motu comes to his rescue and shows him his code. Chotu wants to copy the assignment as quickly as possible but due to the fear of being caught in plagirism check he decides to change all the variable names.
Changing one character to another takes some units of time, Chotu is running out of time so he asks you to calculate the minimum possible time in which he can change a given variable name to another.

NOTE: all the characters in a variable name are in LOWER CASE and the length of old and new variable names is equal for all cases.

INPUT
First line of input contains N the number of variables to be changed.
Next 26 lines contain 26 integers each A(i, j), where the j^th integer on i^th line denotes the time taken to convert i^th character of english alphabet to j^th character.
Next follow 2xN lines containing the Old and the New variable names.
OUTPUT
For each input String output the minimum possible time for conversion.

CONSTRAINTS
1 ≤ N ≤ 100
1 ≤ A(i, j) ≤ 26
1 ≤ |S| ≤ 10^6

SAMPLE INPUT
2
0 1 1 2 1 1 2 1 1 3 3 1 3 1 2 2 1 2 1 1 1 1 3 1 1 1
1 0 1 2 3 2 2 3 1 1 1 2 3 3 1 2 3 1 1 3 2 3 2 1 2 3
1 1 0 3 2 3 2 1 3 3 3 2 2 1 3 1 1 3 2 3 1 3 2 1 2 1
2 2 3 0 1 2 2 3 3 1 3 2 2 1 1 3 2 1 1 3 2 3 1 3 2 1
1 3 2 1 0 3 3 2 3 3 2 1 2 1 3 3 3 2 3 1 3 1 2 1 1 2
1 2 3 2 3 0 1 1 3 3 1 1 2 1 3 1 2 3 1 2 3 3 3 3 1 3
2 2 2 2 3 1 0 1 2 2 2 2 1 1 1 3 1 2 3 3 1 1 2 2 1 1
1 3 1 3 2 1 1 0 3 3 2 1 2 2 3 1 3 1 3 3 2 2 3 1 3 3
1 1 3 3 3 3 2 3 0 3 1 1 1 2 2 3 3 1 1 3 2 3 3 1 1 2
3 1 3 1 3 3 2 3 3 0 1 2 3 2 3 2 3 1 3 3 3 2 1 2 3 2
3 1 3 3 2 1 2 2 1 1 0 3 1 1 3 1 1 3 2 1 1 1 2 3 2 3
1 2 2 2 1 1 2 1 1 2 3 0 2 2 2 2 3 3 1 3 2 3 2 1 3 1
3 3 2 2 2 2 1 2 1 3 1 2 0 2 2 3 1 1 1 3 3 1 2 1 2 2
1 3 1 1 1 1 1 2 2 2 1 2 2 0 3 2 3 2 1 1 2 2 1 1 3 2
2 1 3 1 3 3 1 3 2 3 3 2 2 3 0 3 2 3 1 1 3 1 3 3 1 3
2 2 1 3 3 1 3 1 3 2 1 2 3 2 3 0 3 1 3 3 3 2 3 1 2 2
1 3 1 2 3 2 1 3 3 3 1 3 1 3 2 3 0 3 3 1 3 3 2 1 2 2
2 1 3 1 2 3 2 1 1 1 3 3 1 2 3 1 3 0 3 3 3 2 1 1 2 1
1 1 2 1 3 1 3 3 1 3 2 1 1 1 1 3 3 3 0 1 3 1 2 1 3 3
1 3 3 3 1 2 3 3 3 3 1 3 3 1 1 3 1 3 1 0 3 2 3 3 2 3
1 2 1 2 3 3 1 2 2 3 1 2 3 2 3 3 3 3 3 3 0 2 2 2 2 1
1 3 3 3 1 3 1 2 3 2 1 3 1 2 1 2 3 2 1 2 2 0 3 2 1 1
3 2 2 1 2 3 2 3 3 1 2 2 2 1 3 3 2 1 2 3 2 3 0 3 2 3
1 1 1 3 1 3 2 1 1 2 3 1 1 1 3 1 1 1 1 3 2 2 3 0 3 3
1 2 2 2 1 1 1 3 1 3 2 3 2 3 1 2 2 2 3 2 2 1 2 3 0 2
1 3 1 1 2 3 1 3 2 2 3 1 2 2 3 2 2 1 3 3 1 1 3 3 2 0
arr
brr
inp
mat

SAMPLE OUTPUT
1
4

Explanation

For the first case 'a' in the old string can be converted to 'b' in 1 unit time and rest of the string remains the same.
For the second case i->m takes 1 unit time, n->a takes 1 unit time and p->f->t takes 2 units of time.

输入格式

见题面

输出格式

见题面

样例输入
20 0 2 12 8 25 24 6 12 14 8 14 4 15 8 12 18 2 17 6 21 6 7 17 12 25 15 2 0 15 5 26 17 18 13 8 2 10 15 25 12 2 10 9 10 7 24 11 6 4 5 25 20 12 15 0 11 6 14 22 9 23 11 12 6 6 12 8 19 3 1 18 3 14 13 9 21 15 13 8 5 11 0 6 26 1 18 22 15 21 23 8 8 25 20 16 3 11 7 1 15 19 9 10 13 25 26 6 6 0 24 6 18 17 26 18 9 9 9 10 1 8 4 21 24 21 11 6 3 14 25 24 17 14 26 24 0 5 14 4 1 2 17 7 8 22 14 17 18 23 9 4 15 2 23 7 15 6 18 22 1 6 5 0 16 20 13 3 8 2 19 10 20 1 7 10 20 12 9 11 17 27 15 12 13 9 18 18 14 16 0 12 25 17 5 21 21 11 24 17 19 22 11 20 1 9 27 22 24 14 8 23 22 17 4 20 12 0 1 7 20 4 8 18 6 22 4 26 12 5 5 5 19 3 10 8 2 11 15 26 1 13 25 1 0 19 26 19 2 12 8 7 23 26 19 17 14 25 12 22 18 14 10 12 21 18 2 3 17 7 19 0 6 13 19 16 9 24 22 22 22 22 20 18 8 20 20 4 15 6 23 9 17 8 5 20 26 6 0 1 24 12 19 19 1 14 21 16 17 5 17 10 8 15 25 6 8 9 7 2 21 4 19 13 1 0 10 23 13 6 9 18 20 6 12 7 10 22 13 8 12 12 8 9 8 19 21 8 2 19 24 10 0 14 24 5 22 23 25 16 21 21 24 9 27 12 2 8 25 10 22 10 11 18 12 16 12 23 14 0 11 12 20 2 23 21 24 8 1 14 13 18 10 19 20 1 14 20 24 6 8 9 19 13 24 11 0 3 4 27 19 4 24 9 21 16 15 2 9 3 16 8 17 1 17 22 7 24 19 6 5 12 3 0 22 1 10 3 24 19 9 4 13 17 10 1 3 4 18 7 19 4 23 22 1 9 22 20 4 22 0 6 11 20 6 17 8 17 27 6 7 18 11 21 23 10 22 26 26 22 14 18 23 2 27 1 6 0 9 10 1 15 27 2 18 21 24 3 7 24 9 20 11 12 19 22 21 20 25 23 19 10 11 9 0 4 2 27 21 14 2 6 11 14 1 21 4 12 20 5 17 22 16 6 16 21 4 3 20 10 4 0 15 19 8 23 26 7 6 13 15 11 15 9 1 5 14 20 17 12 21 24 24 24 6 1 2 15 0 16 3 7 17 17 4 9 19 6 2 11 9 5 25 18 5 7 21 8 9 19 17 15 27 19 16 0 7 10 14 12 5 21 9 3 23 17 27 19 12 8 17 10 24 1 21 9 8 27 21 8 3 7 0 19 1 25 25 15 10 14 7 27 22 3 22 20 10 22 9 14 16 4 17 2 14 23 7 10 19 0 11 15 20 13 13 25 15 15 24 10 18 20 8 13 27 13 15 13 27 18 2 26 17 14 1 11 0 qsgculxzkjhwyfeaornd uctwxhfzmalkepnqdrvy qwertyuiop asdfghjklv mpqkxoarfnjhbdtsyvce slxgfoczqbtjvdeawhun rnvkgfeyxutlaqzjhwbs hlpzasnewcfgdytxvrbo jfshwmuvprznkcgedtao judrkealybqosfhngtxv pqzojcwtykbxdlgvfsen ktjwdsozxulpagcyqnvf pagwmxbnlqhfuvkrsoyc mgerojyxduaswlhtfnkq wfxbmlevzyursdthoqjc wvjkfctqpzadyhrnoubx yhvafordestpmbcxnkgq lyfjmbzsgncvdkehaotp wglkcbznrodyamusfpth jbfdxtcloepgasvkuywn avxwbcotpjnydegqumsf bulvqpaysznecrxjmftk agprqsonxevmlwykzbfu rexgoptacljfhdwmzqsb oyrltahqfzcjuwvenxpg hcfvnesqybmdxwaptjur dfpvztcsakujnegmyblh uxtwgdprljzqsehanyvo zyqmprkujntegflocasb mvkadcgqjeshnoluzwyp lfrejgtsqbucvnhzywop ewxnfbzvmlqsophkrudj jyfamzekbtoxnhgrcduw xurbtpfczwvqsyogjdkn ergkhuqltsfyxovjawpn mzudyeqtsfkvrwlohanc hippo killo xagktcnqldyevzmbosjr cnjpuswlmegahvrzfbyt
样例输出
14 421642 420993 422323 421685 421732 420872 421630 420828 421441 422343 422704 421615 422296 422377 420645 423300 422398 420693 422077 421029 420325 422899 421756 421470 421554 420901 422572 421388 421994 421647 421782 421905 421139 421329 420972 421189 422215 421219 421867 422852 421592 421526 422080 421753 421334 421435 422064 422067 421558 422061 421722 421067 421646 422998 421075 422130 421365 420696 421596 420930 421911 422422 421137 422132 420628 421355 422859 421886 421421 421703 421347 421327 421125 422497 422118 421441 420062 422165 422247 421480 422875 421513 421631 421049 421405 423241 422234 421229 421721 420618 421658 421623 420553 421366 422768 422389 421259 420962 420621