#K14546. Maximize Absolute Differences

    ID: 24158 Type: Default 1000ms 256MiB

Maximize Absolute Differences

Maximize Absolute Differences

Given an integer N, arrange the numbers from 1 to N in such a way that the sum of the absolute differences between consecutive elements is maximized. In other words, you need to find a permutation \(P = [P_1, P_2, \dots, P_N]\) of the set \(\{1, 2, \dots, N\}\) such that

\[ \sum_{i=1}^{N-1} |P_{i+1} - P_i| \quad \text{is maximized.} \]

For example, when \(N = 4\), one optimal arrangement is [4, 1, 3, 2] and when \(N = 5\), one optimal arrangement is [5, 1, 4, 2, 3].

inputFormat

The input is read from standard input (stdin). The first line contains a single integer T, the number of test cases. Each of the next T lines contains a single integer N representing the size of the array.

outputFormat

For each test case, output a single line that contains the permutation which maximizes the sum of the absolute differences between consecutive elements. The numbers in the permutation should be space-separated, and each test case's output should be on a new line.

## sample
2
4
5
4 1 3 2

5 1 4 2 3

</p>