409897: GYM103828 J Even Adjacent Product

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Even Adjacent Producttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[1, 2, 4, 3]$$$ is a permutation, but $$$[1, 3, 3, 2]$$$ is not a permutation because $$$3$$$ appears twice in the array, and $$$[1, 2, 4, 5]$$$ is also not a permutation because $$$n = 4$$$ but there is $$$5$$$ in the array.

Your task is to construct a permutation of length $$$n$$$, such that every pair of adjacent numbers in the permutation has an even product.

More formally, for each $$$i$$$ $$$(1 \le i < n)$$$, the following condition must hold:

  • $$$(p_i \times p_{i + 1})$$$ is even.
Input

The first line of input contains a single integer $$$T$$$, the number of test cases.

The next $$$T$$$ lines each contains a single integer $$$(1 \le n \le 10^{5})$$$, the size of the permutation.

The sum of $$$n$$$ over all testcases doesn't exceed $$$10^5$$$.

Output

Print $$$T$$$ lines, each containing a permutation of $$$n$$$ space-separated integers such that every pair of adjacent numbers in the permutation has an even product. if there are multiple answers print any of them.

ExampleInput
2
6
12
Output
2 1 6 5 4 3
2 9 8 7 4 5 6 1 12 3 10 11

加入题单

上一题 下一题 算法标签: