#P1986C. Update Queries
Update Queries
Description
Let's consider the following simple problem. You are given a string of length , consisting of lowercase Latin letters, as well as an array of indices of length () and a string of length , consisting of lowercase Latin letters. Then, in order, you perform the update operations, namely, during the -th operation, you set . Note that you perform all operations from the first to the last.
Of course, if you change the order of indices in the array and/or the order of letters in the string , you can get different results. Find the lexicographically smallest string that can be obtained after update operations, if you can rearrange the indices in the array and the letters in the string as you like.
A string is lexicographically less than a string if and only if one of the following conditions is met:
- is a prefix of , but ;
- in the first position where and differ, the symbol in string is earlier in the alphabet than the corresponding symbol in string .
Each test consists of several sets of input data. The first line contains a single integer () — the number of sets of input data. Then follows their description.
The first line of each set of input data contains two integers and () — the length of the string and the number of updates.
The second line of each set of input data contains a string of length , consisting of lowercase Latin letters.
The third line of each set of input data contains integers () — the array of indices .
The fourth line of each set of input data contains a string of length , consisting of lowercase Latin letters.
It is guaranteed that the sum of over all sets of input data does not exceed . Similarly, the sum of over all sets of input data does not exceed .
For each set of input data, output the lexicographically smallest string that can be obtained by rearranging the indices in the array and the letters in the string as you like.
Input
Each test consists of several sets of input data. The first line contains a single integer () — the number of sets of input data. Then follows their description.
The first line of each set of input data contains two integers and () — the length of the string and the number of updates.
The second line of each set of input data contains a string of length , consisting of lowercase Latin letters.
The third line of each set of input data contains integers () — the array of indices .
The fourth line of each set of input data contains a string of length , consisting of lowercase Latin letters.
It is guaranteed that the sum of over all sets of input data does not exceed . Similarly, the sum of over all sets of input data does not exceed .
Output
For each set of input data, output the lexicographically smallest string that can be obtained by rearranging the indices in the array and the letters in the string as you like.
Note
In the first set of input data, you can leave the array and the string unchanged and simply perform all operations in that order.
In the second set of input data, you can set the array and "zczw". Then the string will change as follows: .
In the third set of input data, you can leave the array unchanged and set "admn". Then the string will change as follows: .