#K57202. Magic Sequence Formation

    ID: 30368 Type: Default 1000ms 256MiB

Magic Sequence Formation

Magic Sequence Formation

You are given an integer k and your task is to determine if a magic sequence of length k can be formed. A magic sequence is defined as a permutation of the integers from 1 to k that satisfies a specific pattern. The rules are as follows:

  • If k = 1, the magic sequence is [1].
  • If k = 2, no valid sequence exists, and the output should be -1.
  • If k = 3, the magic sequence is [1, 2, 3].
  • For higher values of k, only a set of pre-determined sequences are accepted:

The accepted sequences are given by:

  • \( k = 4 \): \( [1, 3, 2, 4] \)
  • \( k = 5 \): \( [1, 4, 3, 2, 5] \)
  • \( k = 6 \): \( [1, 4, 3, 2, 5, 6] \)
  • \( k = 7 \): \( [1, 6, 5, 2, 3, 4, 7] \)
  • \( k = 8 \): \( [1, 6, 5, 2, 3, 4, 7, 8] \)
  • \( k = 9 \): \( [1, 8, 7, 2, 3, 4, 5, 6, 9] \)
  • \( k = 10 \): \( [1, 8, 7, 4, 5, 2, 3, 6, 9, 10] \)

If k does not match any of the above cases, output -1 indicating that forming a magic sequence is not possible.

The input begins with an integer t representing the number of test cases. Each of the following t lines contains one integer k. For each test case, print the magic sequence in one line with numbers separated by a single space, or -1 if no valid sequence exists.

inputFormat

The first line contains a single integer t (1 ≤ t ≤ 100), the number of test cases. Each of the next t lines contains a single integer k (1 ≤ k ≤ 20).

Input is read from standard input (stdin).

outputFormat

For each test case, output a single line. If a magic sequence exists for that test case, print the sequence as a list of numbers separated by a space. Otherwise, print -1.

Output is to standard output (stdout).

## sample
5
1
2
5
7
10
1

-1 1 4 3 2 5 1 6 5 2 3 4 7 1 8 7 4,5,2,3,6,9,10

</p>