A sequence of $n$ numbers is called permutation if it contains all numbers from $1$ to $n$ exactly once. For example, the sequences $[3, 1, 4, 2]$, [$1$] and $[2,1]$ are permutations, but $[1,2,1]$, $[0,1]$ and $[1,3,4]$ are not.

For a given number $n$ you need to make a permutation $p$ such that two requirements are satisfied at the same time:

For each element $p_i$, at least one of its neighbors has a value that differs from the value of $p_i$ by one. That is, for each element $p_i$ ($1 \le i \le n$), at least one of its neighboring elements (standing to the left or right of $p_i$) must be $p_i + 1$, or $p_i - 1$.

the permutation must have no fixed points. That is, for every $i$ ($1 \le i \le n$), $p_i \neq i$ must be satisfied.

Let's call the permutation that satisfies these requirements funny.

For example, let $n = 4$. Then [$4, 3, 1, 2$] is a funny permutation, since:

to the right of $p_1=4$ is $p_2=p_1-1=4-1=3$;

to the left of $p_2=3$ is $p_1=p_2+1=3+1=4$;

to the right of $p_3=1$ is $p_4=p_3+1=1+1=2$;

to the left of $p_4=2$ is $p_3=p_4-1=2-1=1$.

for all $i$ is $p_i \ne i$.

For a given positive integer $n$, output any funny permutation of length $n$, or output -1 if funny permutation of length $n$ does not exist.


-----Input-----

The first line of input data contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

The description of the test cases follows.

Each test case consists of f single line containing one integer $n$ ($2 \le n \le 2 \cdot 10^5$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.


-----Output-----

For each test case, print on a separate line:

any funny permutation $p$ of length $n$;

or the number -1 if the permutation you are looking for does not exist.


-----Examples-----

Input
5
4
3
7
5
2
Output
3 4 2 1
-1
6 7 4 5 3 2 1
5 4 1 2 3
2 1


-----Note-----

The first test case is explained in the problem statement.

In the second test case, it is not possible to make the required permutation: permutations $[1, 2, 3]$, $[1, 3, 2]$, $[2, 1, 3]$, $[3, 2, 1]$ have fixed points, and in $[2, 3, 1]$ and $[3, 1, 2]$ the first condition is met not for all positions.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Constructive algorithms


Solutions:
s = []
for i in range(int(input())):
	a = [str(j) for j in range(1, int(input()) + 1)]
	if len(a) == 1 or len(a) == 3:
		s.append('-1')
	else:
		if len(a) % 2 == 0:
			a.reverse()
		else:
			a = a[2:] + a[:2]
		s.append(' '.join(a))
print('\n'.join(s))


output = []
for caseno in range(int(input())):
	answer = ''
	n = int(input())
	if n == 3:
		answer = '-1'
	else:
		answer = [str(n), str(n - 1)] + [str(i + 1) for i in range(n - 2)]
		answer = ' '.join(answer)
	output.append(answer)
print('\n'.join(output))


n = int(input())
nums = []
for i in range(n):
	nums.append(int(input()))
ans = []
for i in nums:
	if i & 1:
		if i == 3:
			ans.append([-1])
		else:
			res = []
			mid = (i + 1) // 2
			for x in range(mid, i + 1):
				res.append(x)
			for x in range(mid - 1, 0, -1):
				res.append(x)
			ans.append(res)
	else:
		ans.append([x for x in range(i, 0, -1)])
for i in ans:
	res = ' '.join((str(x) for x in i))
	print(res)


import sys
from collections import *
sys.setrecursionlimit(10 ** 5)
itr = (line for line in sys.stdin.read().strip().split('\n'))
INP = lambda : next(itr)

def ni():
	return int(INP())

def nl():
	return [int(_) for _ in INP().split()]

def solve(a):
	if a == 1 or a == 3:
		print(-1)
		return
	out = []
	out.append(a)
	out.append(a - 1)
	for i in range(1, a - 1):
		out.append(i)
	print(' '.join(list(map(str, out))))
t = ni()
for case in range(t):
	a = ni()
	solve(a)


for _ in range(int(input())):
	n = int(input())
	if n % 2 == 0:
		print(' '.join(list(map(str, list(range(n, 0, -1))))))
	elif n > 5:
		sc2 = list(range(n, 0, -1))
		(sc2[n // 2], sc2[n // 2 + 1]) = (sc2[n // 2 + 1], sc2[n // 2])
		print(' '.join(list(map(str, sc2))))
	elif n == 5:
		print('5 4 1 2 3')
	else:
		print('-1')


def funny_seq(number):
	if number == 3:
		return -1
	seq = list(map(lambda x: str(x), range(1, number + 1)))
	return ' '.join([seq[-1], seq[-2]] + seq[:-2])
numbers = [int(input()) for _ in range(int(input()))]
for num in numbers:
	print(funny_seq(num))


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 3 or n == 1:
		print(-1)
		continue
	if n == 2:
		print('2 1')
		continue
	if n == 4:
		print('3 4 2 1')
		continue
	if n == 5:
		print('5 4 1 2 3')
	else:
		a = [n - 1, n] + list(range(1, n - 1))
		a = [str(x) for x in a]
		print(' '.join(a))
		continue


def prob_826B():

	def rotate(l, n):
		return l[n:] + l[:n]
	m = int(input())
	list1 = []
	for i in range(m):
		n = int(input())
		if n == 2:
			list1.append('2 1')
		elif n == 3:
			list1.append(-1)
		else:
			test = [i for i in range(1, n + 1)]
			test = rotate(test, 2)
			string_list = [str(j) for j in test]
			list1.append(' '.join(string_list))
	for i in list1:
		print(i)
prob_826B()


n = int(input())
kq = []
for i in range(n):
	p = int(input())
	ls = list(range(1, p + 1))
	if len(ls) % 2 == 0:
		kq.append(list(reversed(ls)))
	elif len(ls) == 3:
		kq.append([-1])
	else:
		ls = list(reversed(ls))
		kq.append(ls[:len(ls) // 2] + list(reversed(ls[len(ls) // 2:])))
for i in kq:
	i = list(map(str, i))
	print(' '.join(i))


t = int(input())
for _ in range(t):
	n = int(input())
	if n % 2 == 0:
		print(' '.join([str(x) for x in range(n, 0, -1)]))
	elif n == 3:
		print('-1')
	else:
		a = [n - 1, n] + [x for x in range(1, n - 1)]
		print(' '.join([str(x) for x in a]))


def get_funny_permutation(n):
	if n == 3:
		return -1
	elif n % 2 == 0:
		temp = [x for x in range(n, 0, -1)]
		return ' '.join(map(str, temp))
	else:
		temp = [x for x in range(n, 0, -1)]
		temp[-len(temp) // 2:] = temp[-len(temp) // 2:][::-1]
		return ' '.join(map(str, temp))

def main():
	t = int(input())
	for _ in range(t):
		f = int(input())
		ans = get_funny_permutation(f)
		print(ans)
main()


for i in range(int(input())):
	x = int(input())
	if x % 2 == 0:
		print(' '.join([str(i) for i in range(x, 0, -1)]))
	elif x == 3:
		print(-1)
	elif x == 5:
		print('5 4 1 2 3')
	else:
		m = [str(i) for i in range(x, 0, -1)]
		(m[len(m) // 2], m[len(m) // 2 + 1]) = (m[len(m) // 2 + 1], m[len(m) // 2])
		print(' '.join(m))


n = int(input())
A = []
res = []
res1 = []
for i in range(n):
	a = int(input())
	A.append(a)
for i in range(len(A)):
	ans = ''
	res = []
	if A[i] == 3:
		print(-1)
	elif A[i] % 2 == 0:
		for i in range(1, A[i] + 1):
			res.append(i)
		res = res[::-1]
		ans = ' '.join(map(str, res))
		print(ans)
	else:
		ans1 = ''
		ans1 += str(A[i]) + ' ' + str(A[i] - 1) + ' '
		for i in range(1, A[i] - 1):
			ans1 += str(i) + ' '
		print(ans1)


t = int(input())

def funny_per(n):
	lista = [i + 1 for i in reversed(range(n))]
	lon = len(lista)
	if lon == 3:
		value = [-1]
	elif lon % 2 == 0:
		value = lista
	elif lon == 5:
		a = (lista[0], lista[2])
		lista[2] = a[0]
		lista[0] = a[1]
		value = lista
	else:
		item = lon // 2
		a = (lista[item], lista[item - 1])
		lista[item - 1] = a[0]
		lista[item] = a[1]
		value = lista
	return value
for i in range(t):
	n = int(input())
	result = funny_per(n)
	print(' '.join(map(str, result)))


def main():
	tests = int(input())
	for _ in range(tests):
		current = int(input())
		per = []
		if current == 3:
			print(-1)
			continue
		for i in range(3, current + 1):
			per.append(str(i))
		per += ['2', '1']
		string = ' '.join(per)
		print(string)
main()


import itertools
for _ in range(int(input())):
	n = int(input())
	if n in [1, 3]:
		print(-1)
	elif n % 2 == 0:
		print(' '.join(map(str, range(n, 0, -1))))
	else:
		print(' '.join(map(str, itertools.chain(range(n, n // 2 + 1, -1), range(1, n // 2 + 2)))))


for i in range(int(input())):
	n = int(input())
	ans = []
	if n == 3:
		print(-1)
	else:
		if n % 2 == 0:
			ans = [i for i in range(n, 0, -1)]
		else:
			for i in range(n, n // 2 + 1, -1):
				ans.append(i)
			for i in range(1, n // 2 + 2):
				ans.append(i)
		print(' '.join(map(str, ans)))


t = int(input())
for i in range(t):
	n = int(input())
	l = [i for i in range(1, n + 1)]
	if n == 1 or n == 3:
		print(-1)
	elif n == 2:
		print(' '.join([str(l[1]), str(l[0])]))
	else:
		l1 = []
		l1 = l[2:] + l[:2]
		l1 = [str(i) for i in l1]
		print(' '.join(l1))


from math import gcd

def main():
	n_tests = int(input())
	for _ in range(n_tests):
		n = int(input())
		if n == 3:
			print(-1)
			continue
		if n % 2 == 0:
			print(' '.join(map(str, reversed(range(1, n + 1)))))
			continue
		data = list(range(1, n + 1))
		start = [data[-1], data[-2]] + data[:len(data) - 2]
		print(' '.join(map(str, start)))
main()


l = int(input())
for i in range(l):
	n = int(input())
	if n == 3:
		print(-1)
	elif n == 1:
		print(-1)
	elif n == 5:
		print('4 5 1 2 3')
	elif n % 2 == 0:
		list_n = [str(x) for x in list(range(n, 0, -1))]
		print(' '.join(list_n))
	else:
		list_n = [str(x) for x in list(range(n, 0, -1))]
		popnum = list_n.pop(int(n / 2))
		list_n.insert(int(n / 2 - 1), popnum)
		print(' '.join(list_n))


n = int(input())
nn = []
for i in range(n):
	nn.append(int(input()))
for i in range(n):
	x = nn[i]
	if x == 1:
		print(1)
	elif x == 2:
		print('2 1')
	elif x == 3:
		print(-1)
	elif x % 2 == 0:
		print(''.join([f'{i} ' for i in range(x, 0, -1)])[:-1])
	else:
		m = x // 2
		l = list(range(1, x + 1))[::-1]
		print(''.join((f'{i} ' for i in l[:m] + l[m:][::-1])))


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		if n > 3:
			l = [str(n - 1), str(n)]
			for j in range(1, n - 1):
				l.append(str(j))
			print(' '.join(l))
		elif n == 2:
			print('2 1')
		elif n == 3:
			print('-1')
main()


import os
import math
import collections
import bisect
import functools
import itertools
import heapq

def solve(n):
	if n == 2:
		return [2, 1]
	if n == 3:
		return [-1]
	if n % 2 == 0:
		return list(range(n, 0, -1))
	m = (n + 1) // 2
	return list(range(n, m, -1)) + list(range(1, m + 1))
t = int(input())
for _ in range(t):
	n = int(input())
	print(' '.join((str(x) for x in solve(n))))


def perm(n: int):
	if n == 3:
		return (-1,)
	if n % 2:
		return (n, n - 1, *tuple(range(1, n - 1, 1)))
	else:
		return tuple(range(n, 0, -1))
for _ in range(int(input())):
	n = int(input())
	print(' '.join(map(str, perm(n))))


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 3:
		print(-1)
	elif n % 2 == 0:
		out = [x for x in range(n, 0, -1)]
		print(' '.join(list(map(str, out))))
	else:
		out = [x for x in range(n, n // 2 + 1, -1)] + [x for x in range(1, n // 2 + 2)]
		print(' '.join(list(map(str, out))))


import math
import re

def solve():
	n = int(input())
	if n == 3:
		return -1
	ans = [n - x for x in range(n)]
	if n % 2 == 0:
		pass
	elif n == 5:
		(ans[(n + 1 >> 1) - 1], ans[(n + 1 >> 1) + 1]) = (ans[(n + 1 >> 1) + 1], ans[(n + 1 >> 1) - 1])
	else:
		(ans[(n + 1 >> 1) - 1], ans[n + 1 >> 1]) = (ans[n + 1 >> 1], ans[(n + 1 >> 1) - 1])
	return ' '.join(map(str, ans))
for _ in range(int(input())):
	print(solve())


def solve2():
	n = int(input())
	ans = []
	for i in range(n, 0, -1):
		ans.append(i)
	if n % 2 == 0:
		return ' '.join([str(i) for i in ans])
	if n == 3:
		return -1
	else:
		al = n // 2
		new = ans[:al]
		for x in ans[al:][::-1]:
			new.append(x)
		return ' '.join([str(i) for i in new])
test = int(input())
for _ in range(test):
	ans = solve2()
	print(ans)


def main():
	for _ in range(int(input())):
		n = int(input())
		print(str(' '.join(map(str, get_answ(n)))))

def get_answ(n):
	answ = []
	if n == 2:
		answ = [2, 1]
		return answ
	elif n == 3:
		answ = [-1]
		return answ
	else:
		answ = [n, n - 1]
		for i in range(1, n - 1):
			answ.append(i)
		return answ
main()


t = int(input())
for i in range(t):
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
		continue
	b = [str(i) for i in range(n, 0, -1)]
	if n % 2 == 0:
		print(' '.join(b))
		continue
	s = b[len(b) // 2:len(b)]
	s.reverse()
	s = b[0:len(b) // 2] + s
	print(' '.join(s))


t = int(input())
for i in range(t):
	n = int(input())
	if n == 3:
		print(-1)
		continue
	if n == 2:
		print('2 1')
		continue
	pref = list(range(n, n - n // 2, -1))
	suff = list(range(1, n // 2 + 1 + n % 2))
	print(' '.join(map(str, pref)), end=' ')
	print(' '.join(map(str, suff)))


T = int(input())
for i in range(T):
	N = int(input())
	if N == 3:
		print(-1)
	elif N == 5:
		print('5 4 1 2 3')
	elif N % 2 == 0:
		res = [str(x) for x in range(N, 0, -1)]
		print(' '.join(res))
	else:
		res = [str(x) for x in range(N, 0, -1)]
		(res[N // 2], res[N // 2 + 1]) = (res[N // 2 + 1], res[N // 2])
		print(' '.join(res))


import math
t = int(input())
while t > 0:
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
	else:
		half = math.ceil(n / 2)
		res = []
		for i in range(n, half, -1):
			res.append(i)
		for i in range(1, half + 1):
			res.append(i)
		print(' '.join(map(str, res)))
	t -= 1


def f(n):
	l = []
	for i in range(3, n + 1):
		l.append(i)
	l.append(1)
	l.append(2)
	return l
t = int(input())
while t != 0:
	n = int(input())
	if n == 3:
		print(-1)
	elif n == 2:
		print(2, 1)
	else:
		m = ' '
		print(m.join(map(str, f(n))))
	t -= 1


nbTest = int(input())
for testN in range(nbTest):
	n = int(input())
	res = []
	if n == 2:
		res = ['2', '1']
	elif n == 3:
		res = ['-1']
	else:
		res.append(str(n))
		res.append(str(n - 1))
		for i in range(1, n - 1):
			res.append(str(i))
	print(' '.join(res))


for _ in range(int(input())):
	n = int(input())
	if n == 3:
		print(-1)
		continue
	out1 = []
	for x in range(n, n - 2, -1):
		out1.append(str(x))
	for x in range(1, n - 1):
		out1.append(str(x))
	print(' '.join(out1))


def sol(n):
	l = [str(_) for _ in range(1, n + 1)]
	if n == 3:
		return '-1'
	else:
		p = ' '.join(l[n // 2:]) + ' ' + ' '.join(l[:n // 2])
		return p
t = int(input())
for _ in range(t):
	n = int(input())
	print(sol(n))


x = int(input())
for i in range(x):
	a = int(input())
	if a == 2:
		print('2 1')
	elif a == 3:
		print(-1)
	else:
		res = []
		if a % 2:
			srt = 4
		else:
			srt = 3
		for i in range(srt, a + 1):
			res.append(str(i))
		for i in range(1, srt):
			res.append(str(i))
		print(' '.join(res))


test = int(input())
for i in range(0, test):
	state = []
	n = int(input())
	if n == 1 or n == 3:
		state.append(-1)
	elif n == 2:
		state.append(2)
		state.append(1)
	else:
		state.append(n - 1)
		state.append(n)
		for j in range(1, n - 1):
			state.append(j)
	state = ' '.join(map(str, state))
	print(state)


size = input()
for i in range(int(size)):
	n = int(input())
	if n == 2:
		print(2, 1)
		continue
	if n == 3:
		print(-1)
		continue
	if n == 5:
		print(5, 4, 1, 2, 3)
		continue
	if n % 2 == 0:
		print(' '.join([str(i) for i in range(n, 0, -1)]))
	else:
		print(' '.join([str(i) for i in range(n, (n + 1) // 2, -1)] + [str((n + 1) // 2 - 1), str((n + 1) // 2)] + [str(i) for i in range((n + 1) // 2 - 2, 0, -1)]))


import sys
import threading
from functools import lru_cache
from collections import defaultdict, deque

def main():
	t = int(input())
	for k in range(t):
		n = int(input())
		if n == 3:
			print(-1)
			continue
		ans = deque()
		if n % 2 == 0:
			print(' '.join(map(str, range(n, 0, -1))))
		else:
			ans = []
			mid = n // 2
			for i in range(mid + 1, n + 1):
				ans.append(str(i))
			for i in range(1, mid + 1):
				ans.append(str(i))
			print(' '.join(ans))
sys.setrecursionlimit(1 << 30)
threading.stack_size(1 << 27)
main_thread = threading.Thread(target=main)
main_thread.start()
main_thread.join()


t = int(input())
for i in range(t):
	n = int(input())
	if n == 3:
		print(-1)
	elif n % 2 == 0:
		r = list(range(1, n + 1))
		r.reverse()
		print(' '.join(map(str, r)))
	else:
		r = list(reversed(list(range(1, n + 1))[n // 2 + 1:])) + list(range(1, n + 1))[0:n // 2 + 1]
		print(' '.join(map(str, r)))


import math

def permutation(num):
	lst = []
	if num % 2 == 0:
		for i in range(1, num + 1):
			lst.append(str(i))
		lst.reverse()
	else:
		for i in range(int(math.floor(num / 2)) + 1, num + 1):
			lst.append(str(i))
		for i in range(1, int(math.floor(num / 2)) + 1):
			lst.append(str(i))
	print(' '.join((i for i in lst)))
	return
t = int(input())
for i in range(t):
	n = int(input())
	if n == 1 or n == 3:
		print('-1')
	else:
		permutation(int(n))


def solve():
	n = int(input())
	if n == 1:
		print('1')
		return
	if n == 2:
		print('2 1')
		return
	if n == 3:
		print('-1')
		return
	s = []
	for i in range(1, n + 1):
		s.append(str(i))
	s = s[-2:] + s[:n - 2]
	print(' '.join(s))
for _ in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	list = [x for x in range(1, n + 1)]
	if n == 3:
		print('-1')
	else:
		a = list.pop(0)
		a = list.pop(0)
		list.append(2)
		list.append(1)
		print(' '.join([str(x) for x in list]))


t = int(input())
for i in range(t):
	n = int(input())
	if n == 3:
		print(-1)
		continue
	ans = [str(n), str(n - 1)]
	for i in range(1, n - 1):
		ans.append(str(i))
	print(' '.join(ans))


t = int(input())
for l in range(t):
	olist = []
	n = int(input())
	if n == 3:
		print('-1')
	else:
		for j in range(3, n + 1):
			olist.append(j)
		if n % 2 == 0:
			olist.append(2)
			olist.append(1)
			olist.sort(reverse=True)
			print(' '.join(map(str, olist)))
		else:
			olist.append(2)
			olist.append(1)
			print(' '.join(map(str, olist)))


t = int(input())
for ncase in range(1, t + 1):
	n = int(input())
	if n == 2:
		ans = '2 1'
	elif n == 3:
		ans = '-1'
	elif n % 2 == 0:
		ans = ' '.join([str(i) for i in range(n, 0, -1)])
	else:
		ans = ' '.join([str(i) for i in range(n, int((n + 1) / 2), -1)] + [str(i) for i in range(1, int((n + 3) / 2))])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	if n == 3 or n == 1:
		print(-1)
	else:
		ans = [str(i) for i in range(1, n + 1)]
		if n % 2:
			print(' '.join(ans[n // 2:n] + ans[:n // 2]))
		else:
			print(' '.join(ans[::-1]))


for _ in range(int(input())):
	n = int(input())
	if n == 3:
		print(-1)
	elif n % 2 == 0:
		print(' '.join(map(str, [i + 1 for i in reversed(range(n))])))
	else:
		out = [n, n - 1]
		out += [i + 1 for i in range(n - 2)]
		print(' '.join(map(str, out)))


time = int(input())
for i in range(time):
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
	elif n == 2:
		print('2 1')
	else:
		l = [str(n - 1), str(n)] + [str(x) for x in range(1, n - 1)]
		print(' '.join(l))


for _ in range(int(input())):
	s = list(map(str, range(1, 1 + int(input()))))
	print(-1 if len(s) == 3 else ' '.join(s[2:] + list(reversed(s[:2]))))


t = int(input())
for h in range(t):
	arr = []
	n = int(input())
	if n == 3 or n == 1:
		print('-1')
	else:
		arr.append(str(n))
		arr.append(str(n - 1))
		for i in range(1, n - 1):
			arr.append(str(i))
		st = ' '.join(arr)
		print(st)


from functools import lru_cache as cache
from collections import Counter, defaultdict, deque
import math
import bisect
import string
from heapq import *
import sys

def get_int():
	return int(input())

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_str():
	return sys.stdin.readline().strip()

def main():
	testcases = get_int()
	for _ in range(testcases):
		n = get_int()
		print(solve(n))

def solve(n):
	if n == 3:
		return -1
	if n == 2:
		return '2 1'
	result = [i for i in range(3, n + 1)]
	result += [2, 1]
	return ' '.join(map(str, result))
main()


testcases = int(input())

def reverse(n):
	newList = []
	for x in range(0, len(n)):
		newList.append(n[len(n) - x - 1])
	return newList
for i in range(testcases):
	t = int(input())
	perm = []
	for j in range(1, t + 1):
		perm.append(str(j))
	perm.reverse()
	if t == 3:
		print(-1)
		continue
	if t % 2 == 1:
		rev = reverse(perm[int(t / 2):t])
		for j in range(int(t / 2), t):
			perm[j] = rev[j - int(t / 2)]
	print(' '.join(perm))


t = int(input())
for i in range(t):
	n = int(input())
	if n == 3:
		print('-1')
	if n % 2 == 0:
		lis = []
		for j in range(1, n + 1):
			lis.append(str(n - j + 1))
		print(' '.join(lis))
	if n % 2 != 0 and n != 3:
		count = (n + 1) // 2
		lis = []
		for j in range(count, n + 1):
			lis.append(str(j))
		for j in range(n - count):
			lis.append(str(j + 1))
		print(' '.join(lis))


for i in range(int(input())):
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
	elif n == 2:
		print('2 1')
	else:
		print(str(n - 1), str(n), ' '.join(map(str, range(1, n - 1))))


def make_funny_permutation(n):
	if n == 3:
		return -1
	x = [str(i) for i in range(n // 2 + 1, n + 1)]
	y = [str(i) for i in range(1, n // 2 + 1)]
	x.extend(y)
	return ' '.join(x)
num = int(input())
for i in range(num):
	n = int(input())
	print(make_funny_permutation(n))


n = int(input())
for i in range(n):
	j = int(input())
	if j % 2 == 0:
		arr = [k for k in range(1, j + 1)]
		print(' '.join(map(str, arr[::-1])))
	elif j == 3:
		print(-1)
	else:
		arr = [k for k in range(1, j + 1 - 2)]
		arr.insert(0, j - 1)
		arr.insert(1, j)
		print(' '.join(map(str, arr)))


def f(n):
	if n == 1 or n == 3:
		return -1
	if n == 2:
		return '2 1'
	res = [(i + n - 2) % n + 1 for i in range(n)]
	return ' '.join(map(str, res))
t = int(input())
for i in range(t):
	n = int(input())
	print(f(n))


class Solution:

	def produceValid(n: int):
		nums = [j for j in range(n, n - 2, -1)] + [i for i in range(1, n - 1)]
		for k in range(n):
			if k + 1 == nums[k]:
				return -1
		str_nums = [str(num) for num in nums]
		return ' '.join(str_nums)

	def funnyPermutation():
		n = int(input())
		for length in range(n):
			length = int(input())
			print(Solution.produceValid(length))
Solution.funnyPermutation()


for _ in range(int(input())):
	P = int(input())
	if P == 3:
		print(-1)
	else:
		print(P, P - 1, ' '.join(map(str, range(1, P - 1))))


tmp = [str(i) for i in range(3, 200001)]
for i in range(int(input())):
	n = int(input())
	if n == 3:
		print(-1)
	else:
		print(' '.join(tmp[:n - 2]) + ' 2 1')


import string
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
t = int(input())
for _ in range(t):
	n = int(input())
	if n % 2 == 0:
		A = [i + 1 for i in range(n)]
		A.reverse()
		print(' '.join(map(str, A)))
	elif n == 3:
		print(-1)
	else:
		A = [i + 1 for i in range(n)]
		A1 = A[-2:]
		A2 = A[:-2]
		A = A1 + A2
		print(' '.join(map(str, A)))


m = 998244353
T = int(input())
for t in range(T):
	n = int(input())
	if n == 3:
		print(-1)
	elif n % 2 == 0:
		out = ''
		for i in range(n // 2):
			out += str(n - i) + ' '
		for i in range(n // 2):
			out += str(i + 1) + ' '
		print(out)
	else:
		out = ''
		for i in range(n // 2):
			out += str(n - i) + ' '
		for i in range(n // 2):
			out += str(i + 1) + ' '
		out += str((n + 1) // 2)
		print(out)


def gcd(y, z):
	while z:
		(y, z) = (z, y % z)
	return abs(y)

def solve():
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
		return
	res = ''
	if n % 2:
		for i in range(n // 2):
			res += str(n - i) + ' '
		for i in range(n // 2 + 1):
			res += str(i + 1) + ' '
		print(res[:len(res) - 1])
	else:
		for i in range(n, 0, -1):
			res += str(i) + ' '
		print(res[:len(res) - 1])
t = int(input())
for _ in range(t):
	solve()


def helper(n):
	p = [i for i in range(1, n + 1)]
	p = p[::-1]
	for i in range(1, len(p)):
		if p[i] == i + 1 and i > 1:
			p[i:] = p[i:][::-1]
		elif p[i] == i + 1 and i == 1:
			return -1
	return ' '.join(list(map(str, p)))
for i in range(int(input())):
	n = int(input())
	res = helper(n)
	print(res)


tmp = [str(i) for i in range(200000, 0, -1)]
for i in range(int(input())):
	n = int(input())
	if n % 2:
		if n == 3:
			print(-1)
		else:
			print(' '.join(tmp[-n:-(n // 2 + 1)]) + ' ' + ' '.join(tmp[-(n // 2 + 1):][::-1]))
	else:
		print(' '.join(tmp[-n:]))


def N():
	return int(input())

def A():
	return [x for x in input().split()]

def S():
	return input()
for _ in range(N()):
	if 'er9fj48gh48gh4' == 14194665565:
		print('Tanmay')
	n = N()
	if n == 3:
		print(-1)
		continue
	ans = ''
	if n % 2:
		ans = str(n - 1) + ' ' + str(n) + ' '
		for i in range(1, n - 1):
			ans += str(i) + ' '
	else:
		for i in range(n, 0, -1):
			ans += str(i) + ' '
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 3:
		print(-1)
		continue
	k = n // 2
	out = [str(i) for i in range(k + 1, n + 1)] + [str(j) for j in range(1, k + 1)]
	print(' '.join(out))


n = int(input())
while n > 0:
	n = n - 1
	k = int(input())
	L = []
	K = []
	if k == 3:
		print(-1)
	else:
		for i in range(1, k + 1):
			L.append(i)
			K.append(i)
		L.reverse()
		if k % 2 == 0:
			print(' '.join(map(str, L)))
		else:
			print(' '.join(map(str, L[:k // 2])) + ' ' + ' '.join(map(str, K[:k // 2 + 1])))


t = int(input())
for _ in range(0, t):
	n = int(input())
	if n == 2:
		print(f'2 1')
	elif n == 3:
		print('-1')
	elif n % 2 == 0:
		s = ''
		for i in range(n, 0, -1):
			s += str(i) + ' '
		print(s)
	else:
		s = str(n) + ' ' + str(n - 1) + ' '
		for i in range(1, n - 1):
			s += str(i) + ' '
		print(s)


def solve():
	n = int(input())
	a = []
	for i in range(0, n):
		a.append(i + 1)
	mid = n // 2
	if n % 2 != 0:
		mid += 1
	aa = a[:mid]
	bb = a[mid:]
	bb.reverse()
	bb.extend(aa)
	flag = 0
	for i in range(0, n):
		if bb[i] == i + 1:
			flag = 1
			break
	if flag or n == 3:
		print(-1)
	else:
		print(' '.join((str(x) for x in bb)))
for t in range(0, int(input())):
	solve()


t = int(input())
for c in range(t):
	n = int(input())
	s = ''
	if n == 3:
		print(-1)
	else:
		for i in range(n):
			if i < 2:
				s += str(n - i) + ' '
			else:
				s += str(i - 1) + ' '
		print(s)


for i in range(int(input())):
	n = int(input())
	if n == 3:
		print(-1)
		continue
	s = str(n) + ' ' + str(n - 1) + ' '
	for i in range(1, n - 1):
		s += str(i) + ' '
	print(s)


n = int(input())
for _ in range(n):
	a = int(input())
	if a == 3:
		print(-1)
	elif a == 2:
		print('2 1')
	else:
		s = ' '
		for i in range(1, a - 1):
			s += str(i) + ' '
		s = str(a - 1) + ' ' + str(a) + s
		print(s)


for i in range(int(input())):
	n = int(input())
	str = ''
	if n == 3:
		print(-1)
	else:
		if n % 2 == 0:
			for i in range(n, 0, -1):
				str += f'{i} '
		else:
			for i in range(n, n // 2 + 1, -1):
				str += f'{i} '
			for i in range(1, n - n // 2 + 1):
				str += f'{i} '
		print(str)


def permute(array):
	text = ''
	new = []
	if len(array) > 3:
		half = int(len(array) / 2)
		new = [array[half:], array[:half]]
		new = [el for first in new for el in first]
	else:
		reversed = array[::-1]
		for (i, x) in enumerate(reversed):
			if i + 1 == x:
				return '-1'
			else:
				continue
		new = reversed.copy()
	for elem in new:
		text += str(elem) + ' '
	return text
for _ in range(int(input())):
	n = int(input())
	if n < 2:
		print(-1)
	else:
		funny = permute(list(range(1, n + 1)))
		print(funny)


num = int(input())
for i in range(num):
	n = int(input())
	if n == 2:
		print('2 1')
	elif n == 3:
		print(-1)
	elif n == 5:
		print('4 5 1 2 3')
	else:
		j = n
		ans = ''
		while j > 3:
			if j - 1 > 3:
				if (j - 1) * 2 == n:
					ans += f'{j} {j - 1} '
				else:
					ans += f'{j - 1} {j} '
			else:
				ans += f'{j} '
			j -= 2
		ans += '3 2 1'
		print(ans)


def check_is_fun(l):
	state = True
	for i in range(1, len(l) - 1):
		if not (l[i] + 1 == l[i + 1] or l[i] - 1 == l[i + 1] or l[i] + 1 == l[i - 1] or (l[i] - 1 == l[i - 1])):
			state = False
	if not (l[-1] + 1 == l[-2] or l[-1] - 1 == l[-2]):
		state = False
	return state
n = int(input())
for i in range(n):
	a = []
	cur_len = int(input())
	if cur_len == 2:
		print('2 1')
	elif cur_len == 3:
		print(-1)
	else:
		for i in range(3, cur_len + 1):
			a.append(i)
		res = a + [2, 1]
		if check_is_fun(res):
			print(' '.join((str(elem) for elem in res)))
		else:
			print(-1)


def solution(n):
	if n == 3:
		s = '-1 '
	elif n == 2:
		s = '2 1 '
	else:
		res = [n - 1, n]
		res += [i for i in range(1, n - 1)]
		s = ''
		for x in res:
			s += str(x) + ' '
	print(s[:-1])
t = int(input())
for i in range(t):
	z = int(input())
	solution(z)


t = int(input(''))
for i in range(0, t):
	n = int(input(''))
	if n == 3:
		print(-1)
	elif n % 2 == 0:
		l = ''
		for i in range(n, 0, -1):
			l += str(i) + ' '
		print(l)
	elif n % 2 != 0:
		l = ''
		for i in range((n + 1) // 2, n):
			l += str(i + 1) + ' '
		for i in range(0, (n + 1) // 2):
			l += str(i + 1) + ' '
		print(l)


for _ in range(int(input())):
	n = int(input())
	s = ''
	if n != 3 and n != 1 and (n != 5):
		if n % 2 == 0:
			for i in range(n, 0, -1):
				s += str(i) + ' '
			print(s)
		else:
			S = []
			for i in range(n, 0, -1):
				S.append(i)
			temp = S[n // 2 - 1]
			S[n // 2 - 1] = S[n // 2]
			S[n // 2] = temp
			for ele in S:
				s += str(ele) + ' '
			print(s)
	elif n == 5:
		print('5 4 1 2 3')
	else:
		print(-1)


n = int(input())
for i in range(n):
	m = int(input())
	if m == 3 or m == 1:
		print(-1)
	elif m % 2:
		ans = ''
		for e in range(m, 3, -2):
			ans += str(e - 1) + ' ' + str(e) + ' '
		ans += '1 2 3'
		print(ans)
	else:
		print(*range(m, 0, -1))


t = int(input())
for i in range(t):
	n = int(input())
	s = ''
	a = ''
	if n == 1 or n == 3:
		print(-1)
	elif n % 2 == 0:
		for j in range(n, 0, -1):
			s += str(j) + ' '
		print(s)
	elif n % 2 != 0:
		a = a + str(n - 1) + ' ' + str(n) + ' '
		for j in range(1, n - 1):
			a += str(j) + ' '
		print(a)


for i in range(int(input())):
	n = int(input())
	if n == 3 or n == 1:
		print(-1)
	else:
		print(n, n - 1, *range(1, n - 1))


t = int(input())
out = ''
for _ in range(t):
	n = int(input())
	if n == 3:
		out += '-1\n'
		continue
	ans = str(n) + ' ' + str(n - 1) + ' '
	for x in range(1, n - 1):
		ans += str(x) + ' '
	out += ans + '\n'
print(out)


def fast_sum(a, b, s):
	b -= (b - a) % s
	return int((a + b) / 2 * ((b - a) / s + 1))

def main():
	for _ in range(int(input())):
		n = int(input())
		if n == 3:
			print(-1)
			continue
		if n % 2 == 0:
			print(*list(range(1, n + 1))[::-1])
		else:
			r = [n - 1, n] + list(range(1, n - 1))
			print(*r)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 2:
		print('2 1')
	elif n == 3:
		print(-1)
	else:
		print(n, n - 1, end=' ')
		print(*[i for i in range(1, n - 1)])


(n, ans) = (int(input()), [])
for i in range(n):
	s = int(input())
	if s != 3 and s != 1:
		ans.append([m for m in range(s // 2 + 1, s + 1)] + [l for l in range(1, s // 2 + 1)])
	else:
		ans.append([-1])
for n in ans:
	print(*n)


t = int(input())
result = []
for i in range(t):
	n = int(input())
	if n == 2:
		result.append('2 1')
	elif n == 3:
		result.append('-1')
	else:
		ch = ''
		if n % 2 == 1:
			for j in range(n, 3, -2):
				ch += str(j - 1) + ' ' + str(j) + ' '
			ch += '1 2 3'
		else:
			for j in range(n, 2, -1):
				ch += str(j) + ' '
			ch += '1 2'
		result.append(ch)
for i in result:
	print(i)


import string
for _ in range(int(input())):
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
	elif n == 2:
		print('2 1')
	else:
		a = ''
		for i in range(3, n + 1):
			a += str(i) + ' '
			if i == n:
				a += '2 1 '
		print(a)


def permute(N):
	if N == 3 or N == 1:
		return [-1]
	if N == 5:
		return [5, 4, 1, 2, 3]
	if N % 2 == 0:
		return list(range(1, N + 1))[::-1]
	else:
		lt = list(range(1, N + 1))[::-1]
		temp = lt[N // 2]
		lt[N // 2] = lt[N // 2 - 1]
		lt[N // 2 - 1] = temp
		return lt
OUTPUT = []
for _ in range(int(input())):
	N = int(input())
	OUTPUT.append(permute(N))
for _ in OUTPUT:
	print(*_)