#C9490. Organize Gemstones

    ID: 53589 Type: Default 1000ms 256MiB

Organize Gemstones

Organize Gemstones

You are given data about several days of gemstone collections. For each day, the input provides the day number, the count of gemstones for that day, and the list of gemstones. Alice has a unique method for organizing her gemstones:

  • If the day number is odd, sort the gemstones in descending order. That is, if we denote the day by \(d\), when \(d \bmod 2 \neq 0\) the gemstones should be sorted such that \(a_1 \ge a_2 \ge \cdots \ge a_n\).
  • If the day number is even, sort the gemstones in ascending order. In other words, when \(d \bmod 2 = 0\) sort such that \(a_1 \le a_2 \le \cdots \le a_n\).

Your task is to reorganize the list of gemstones for each day according to these rules and print the result. Each day’s output should be printed on a new line with the gemstone values separated by spaces.

inputFormat

The first line contains a single integer \(G\) which denotes the number of days. Each of the following \(G\) lines describes a day with the following space-separated integers:

  • The first integer is the day number \(d\).
  • The second integer is the number of gemstones \(n\) for that day.
  • Then follow \(n\) integers representing the gemstone values.

Note: If \(n = 0\) then no gemstone values are provided for that day.

outputFormat

For each day, output a single line containing the reorganized gemstones separated by a single space. For days with no gemstones, output an empty line.

## sample
3
1 5 12 3 5 7 1
2 4 6 8 2 4
3 3 10 15 13
12 7 5 3 1

2 4 6 8 15 13 10

</p>