CF2132A.Homework

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Homework

Vlad and Dima have been assigned a task in school for their English class. They were given two strings aa and bb and asked to append all characters from bb to string aa in any order. The guys decided to divide the work between themselves and, after lengthy negotiations, determined who would add each character from string bb to aa.

Due to his peculiarities, Vlad can only add characters to the beginning of the word, while Dima can only add them to the end. They add characters in the order they appear in string bb. Your task is to determine what string Vlad and Dima will end up with.

Input

Each test consists of several test cases. The first line contains a single integer tt (1t10001 \le t \le 1000) — the number of test cases. The description of the test cases follows.

The first line contains an integer nn (1n101 \le n \le 10) — the length of the string aa.

The second line contains the string aa, consisting of lowercase letters of the English alphabet.

The third line contains an integer mm (1m101 \le m \le 10) — the length of the strings bb and cc.

The fourth line contains the string bb, consisting of lowercase letters of the English alphabet.

The fifth line contains the string cc, consisting of the characters 'V' and 'D' — the distribution of the characters of string bb between Dima and Vlad. If cic_i = 'V', then the ii-th letter is added by Vlad; otherwise, it is added by Dima.

Output

For each test case, output the string that will result from Dima and Vlad's work.

Note

In the first test case, there is initially a string otot. Then Dima appends the character aa to the end of the string, resulting in otaota, and Vlad appends the last character, resulting in dotadota.

In the second test case, the string will change as follows: $efo \rightarrow efor \rightarrow defor \rightarrow deforc \rightarrow odeforc \rightarrow odeforce \rightarrow codeforce \rightarrow codeforces$

In the third test case: $aca \rightarrow acab \rightarrow bacab \rightarrow bacaba \rightarrow abacaba$

In the fourth test case: $biz \rightarrow abiz \rightarrow babiz \rightarrow babizo \rightarrow babizon$

Samples

4
2
ot
2
ad
DV
3
efo
7
rdcoecs
DVDVDVD
3
aca
4
bbaa
DVDV
3
biz
4
abon
VVDD
dota
codeforces
abacaba
babizon

在线编程 IDE

建议全屏模式获得最佳体验