#K40857. Zigzag Books Arrangement

    ID: 26735 Type: Default 1000ms 256MiB

Zigzag Books Arrangement

Zigzag Books Arrangement

Given a list of book identifiers, your task is to arrange them in a zigzag pattern. First, sort the identifiers in descending order and then form a new list by alternately taking the first (largest) and the last (smallest) number from the sorted list. Continue this process until all identifiers have been used. In mathematical form, if the sorted list is \(a_1, a_2, \dots, a_n\) with \(a_1 \ge a_2 \ge \cdots \ge a_n\), then the result should be \(a_1, a_n, a_2, a_{n-1}, \dots\). This pattern must work correctly for both even and odd numbers of elements.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains an integer \(T\) representing the number of test cases.
  • For each test case, the first line contains an integer \(n\) indicating the number of books.
  • The next line contains \(n\) space-separated integers, each representing a book identifier.

outputFormat

For each test case, output a single line to stdout representing the zigzag arrangement. The numbers should be separated by a space.

## sample
2
5
5 3 7 8 2
4
1 4 3 2
8 2 7 3 5

4 1 3 2

</p>