#C5128. Reverse Append Sequence

    ID: 48743 Type: Default 1000ms 256MiB

Reverse Append Sequence

Reverse Append Sequence

Given an initial sequence of numbers \(S\), perform the reverse-append operation repeatedly until the length of \(S\) is at least \(m\). In each operation, let \(S^R\) denote the reverse of \(S\), and the new sequence is formed as:

\(S := S \Vert S^R\)

where \(\Vert\) denotes sequence concatenation. Finally, output the first \(m\) elements of \(S\).

inputFormat

The input begins with an integer \(T\), representing the number of test cases. For each test case, there are two lines:

  • The first line contains two integers \(n\) and \(m\): \(n\) is the initial length of the sequence and \(m\) is the target length.
  • The second line contains \(n\) space-separated integers, which form the initial sequence.

outputFormat

For each test case, output a single line containing \(m\) space-separated integers. These represent the first \(m\) elements of the sequence after repeatedly performing the reverse-append operation.

## sample
1
2 6
1 2
1 2 2 1 1 2

</p>