#K96247. Array Rearrangement Based on Parity

    ID: 39044 Type: Default 1000ms 256MiB

Array Rearrangement Based on Parity

Array Rearrangement Based on Parity

You are given several test cases. In each test case, you are given an integer array of size (N). Your task is to rearrange the array so that all even numbers are sorted in ascending order and placed at the beginning, and all odd numbers are sorted in descending order and appended to the even numbers.

Formally, given an array (A) of (N) integers, partition the array into two subsequences:
(E = {a \in A \mid a \text{ is even}}) and (O = {a \in A \mid a \text{ is odd}}). Sort (E) in increasing order and (O) in decreasing order, then output the concatenation of (E) and (O).

inputFormat

The first line contains an integer (T) denoting the number of test cases. For each test case, the first line contains an integer (N) (the size of the array), followed by a line with (N) space-separated integers.

outputFormat

For each test case, print a single line containing the rearranged array. Numbers are separated by a single space.## sample

2
5
4 3 2 7 6
6
5 4 3 2 1 0
2 4 6 7 3

0 2 4 5 3 1

</p>