#K42747. Beautiful Permutation
Beautiful Permutation
Beautiful Permutation
Given a positive integer \(n\), a permutation \(p = [p_1, p_2, \dots, p_n]\) of the set \(\{1, 2, \dots, n\}\) is called a beautiful permutation if and only if it satisfies the following conditions:
1. When \(n = 1\), the only permutation is [1]
and it is considered beautiful.
2. For \(n \ge 2\), a beautiful permutation exists if and only if \(n\) is even. In this case, the permutation is constructed by swapping every pair of adjacent integers. That is, the permutation becomes:
\[ [2,\ 1,\ 4,\ 3,\ 6,\ 5,\dots,\ n,\ n-1] \]If \(n \ge 2\) and \(n\) is odd, there is no beautiful permutation and you should output NO
.
You are given \(t\) test cases. For each test case, output the beautiful permutation for the given \(n\) in one line. If a beautiful permutation does not exist, print NO
.
inputFormat
The first line of input contains one integer \(t\) (the number of test cases). The following \(t\) lines each contain one integer \(n\).
Input is read from standard input (stdin).
outputFormat
For each test case, print a single line:
- If a beautiful permutation exists (i.e. when \(n=1\) or \(n\) is even), output the permutation as \(n\) space-separated integers.
- If no beautiful permutation exists (i.e. when \(n\) is odd and \(n > 1\)), output
NO
.
Output should be written to standard output (stdout).
## sample3
1
2
3
1
2 1
NO
</p>