codeforces#P1367D. Task On The Board

    ID: 31231 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>constructive algorithmsgreedyimplementationsortings*1800

Task On The Board

Description

Polycarp wrote on the board a string ss containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input.

After that, he erased some letters from the string ss, and he rewrote the remaining letters in any order. As a result, he got some new string tt. You have to find it with some additional information.

Suppose that the string tt has length mm and the characters are numbered from left to right from 11 to mm. You are given a sequence of mm integers: b1,b2,,bmb_1, b_2, \ldots, b_m, where bib_i is the sum of the distances ij|i-j| from the index ii to all such indices jj that tj>tit_j > t_i (consider that 'a'<'b'<...<'z'). In other words, to calculate bib_i, Polycarp finds all such indices jj that the index jj contains a letter that is later in the alphabet than tit_i and sums all the values ij|i-j|.

For example, if tt = "abzb", then:

  • since t1t_1='a', all other indices contain letters which are later in the alphabet, that is: b1=12+13+14=1+2+3=6b_1=|1-2|+|1-3|+|1-4|=1+2+3=6;
  • since t2t_2='b', only the index j=3j=3 contains the letter, which is later in the alphabet, that is: b2=23=1b_2=|2-3|=1;
  • since t3t_3='z', then there are no indexes jj such that tj>tit_j>t_i, thus b3=0b_3=0;
  • since t4t_4='b', only the index j=3j=3 contains the letter, which is later in the alphabet, that is: b4=43=1b_4=|4-3|=1.

Thus, if tt = "abzb", then b=[6,1,0,1]b=[6,1,0,1].

Given the string ss and the array bb, find any possible string tt for which the following two requirements are fulfilled simultaneously:

  • tt is obtained from ss by erasing some letters (possibly zero) and then writing the rest in any order;
  • the array, constructed from the string tt according to the rules above, equals to the array bb specified in the input data.

The first line contains an integer qq (1q1001 \le q \le 100) — the number of test cases in the test. Then qq test cases follow.

Each test case consists of three lines:

  • the first line contains string ss, which has a length from 11 to 5050 and consists of lowercase English letters;
  • the second line contains positive integer mm (1ms1 \le m \le |s|), where s|s| is the length of the string ss, and mm is the length of the array bb;
  • the third line contains the integers b1,b2,,bmb_1, b_2, \dots, b_m (0bi12250 \le b_i \le 1225).

It is guaranteed that in each test case an answer exists.

Output qq lines: the kk-th of them should contain the answer (string tt) to the kk-th test case. It is guaranteed that an answer to each test case exists. If there are several answers, output any.

Input

The first line contains an integer qq (1q1001 \le q \le 100) — the number of test cases in the test. Then qq test cases follow.

Each test case consists of three lines:

  • the first line contains string ss, which has a length from 11 to 5050 and consists of lowercase English letters;
  • the second line contains positive integer mm (1ms1 \le m \le |s|), where s|s| is the length of the string ss, and mm is the length of the array bb;
  • the third line contains the integers b1,b2,,bmb_1, b_2, \dots, b_m (0bi12250 \le b_i \le 1225).

It is guaranteed that in each test case an answer exists.

Output

Output qq lines: the kk-th of them should contain the answer (string tt) to the kk-th test case. It is guaranteed that an answer to each test case exists. If there are several answers, output any.

Samples

输入数据 1

4
abac
3
2 1 0
abc
1
0
abba
3
1 0 1
ecoosdcefr
10
38 13 24 14 11 5 3 24 17 0

输出数据 1

aac
b
aba
codeforces

Note

In the first test case, such strings tt are suitable: "aac', "aab".

In the second test case, such trings tt are suitable: "a", "b", "c".

In the third test case, only the string tt equals to "aba" is suitable, but the character 'b' can be from the second or third position.