#C933. Rearrange Elements
Rearrange Elements
Rearrange Elements
You are given T test cases. In each test case, an integer is provided followed by a list of element identifiers and a permutation of positions. The permutation represents the target positions for each element, where each position is denoted using a 1-indexed system. Your task is to rearrange the elements according to the specified positions and output the rearranged list as a single line of space-separated strings for each case.
For example, if the list of elements is [div1, div2, div3, div4, div5] and the positions are [3, 1, 4, 5, 2], then the rearranged order should be computed as follows: [ \text{arranged}[\text{positions}[i]-1] = \text{elements}[i] ] Thus, the final output is "div2 div5 div1 div3 div4".
inputFormat
The input begins with an integer T, denoting the number of test cases. For each test case:
- The first line contains an integer N, the number of elements.
- The second line contains N space-separated strings representing the element identifiers.
- The third line contains N space-separated integers representing the desired positions (1-indexed) of the corresponding elements.
outputFormat
For each test case, output a single line containing the rearranged element identifiers in order, separated by spaces.## sample
1
3
a b c
1 2 3
a b c
</p>