String Cutting

Let’s consider a string s of length n (0 < n < 10000) containing only characters from a to z. We define a cut ci (0 < i < n) is an action splitting the string s into 2 substrings s1 and s2 so that s1 consists of first i characters of s and s2 consists of remaining characters from s. Each cut is associated with a cost which equals to the total number of characters consisted in either s1 or s2 but not in both. For example, let s = ‘abcbacbd’, the cut c5 will break s into s1 = ‘abcba’ and s2 = ‘cbd’ with the cost of 2. The original string can be cut into k + 1 substrings after applying k cuts sequentially to the string and its subsequent substrings. In order to simply describe these k cuts, we specify the position of the cuts with regard to the original string. Let’s consider an example where we sequentially apply 3 cuts at positions 5, 3 and 6 to the string s = ‘ababccd’. After the first cut at position 5, we have two substrings s1 = ‘ababc’ and s2 = ‘cd’ with the cost of 3. The second cut at position 3 breaks s1 into two substrings s11 = ‘aba’ and s12 = ‘bc’ with the cost of 2. The last cut at position 6 breaks s2 into two substrings s21 = ‘c’ and s22 = ‘d’ with the cost of 2. The total cost for the 3 cuts is 3+2+2=7. Given a string and their cuts, your task is to write a program to compute the total cost for the cut. Input The input consists of several data sets. The first line of the input file contains the number of data sets which is a positive integer and is not bigger than 20. The following lines describe the data sets. For each data set, the first line contains the integer number k (1 ≤ k ≤ 1000). The second line contains k positive integer numbers describing the position of k cuts. The third line contains the string which will be cut. Output For each test case, write in one line the total cost of the cuts. Sample Input 2 3 536 ababccd 2 42 ababcd Sample Output 7 4