#C4324. Beautiful Permutations

    ID: 47850 Type: Default 1000ms 256MiB

Beautiful Permutations

Beautiful Permutations

Bob is fascinated by permutations. He defines a permutation \(p\) of the integers from \(1\) to \(N\) as beautiful if the set of absolute differences \(|p_{i+1} - p_i|\) for \(1 \le i < N\) is exactly \(\{1, 2, \ldots, N-1\}\). In other words, all adjacent differences are pairwise distinct and cover all integers from \(1\) to \(N-1\).

Your task is to help Bob by constructing a beautiful permutation for each given \(N\). It can be shown that for every \(N \ge 1\) there exists at least one beautiful permutation. If more than one answer exists, you may output any one of them.

Input Format: The first line contains a single integer \(T\) denoting the number of test cases. Each of the following \(T\) lines contains an integer \(N\).

Output Format: For each test case, output two lines if a beautiful permutation exists: the first line should print "YES" (without quotes), and the second line should print the beautiful permutation as a sequence of \(N\) space-separated integers. (Note: It is guaranteed that a beautiful permutation always exists.)

Example:

Input:
2
3
4

Output: YES 1 3 2 YES 1 4 2 3

</p>

In the above example, for \(N=3\) the permutation [1, 3, 2] has adjacent differences \(\{2, 1\}\) and for \(N=4\) the permutation [1, 4, 2, 3] has differences \(\{3, 2, 1\}\), both of which satisfy the beautiful permutation condition.

inputFormat

The input is read from standard input and consists of multiple lines. The first line contains a single integer \(T\), the number of test cases. Each of the following \(T\) lines contains one integer \(N\) representing the size of the permutation.

Example:

2
3
4

outputFormat

For each test case, print the answer on two lines. The first line should be "YES" indicating that a beautiful permutation exists. The second line should contain \(N\) space-separated integers representing a beautiful permutation of \(\{1, 2, \ldots, N\}\).

Example:

YES
1 3 2
YES
1 4 2 3
## sample
1
1
YES

1

</p>