A permutation P of length N (1-based) is called good if it satisfies the following these conditions:
For each 1 ≤ i ≤ N, P_{i} \neq i
|P_{1} - 1| \oplus |P_{2} - 2| \oplus \ldots \oplus |P_{N} - N| = 0

Here, \oplus denotes the [bitwise XOR operation] and |X| denotes the absolute value of X.

Find any good permutation P of length N or print -1 if no such permutation exists.

Note: A permutation of length N is an array which contains every integer from 1 to N (inclusive) exactly once.

------ Input Format ------ 

- The first line contains a single integer T - the number of test cases. Then the test cases follow.
- The first and only line of each test case contains an integer N - the length of the permutation P.

------ Output Format ------ 

For each test case, print -1 if no such permutation exists. Otherwise, in a single line, output N space-separated integers - the required good permutation. If more than one solution exists, you may print any of them.

------ Constraints ------ 

$1 ≤ T ≤ 10^{6}$
$1 ≤ N ≤ 10^{6}$
- Sum of $N$ over all test cases does not exceed $10^{6}$

----- Sample Input 1 ------ 
3
1
2
8
----- Sample Output 1 ------ 
-1
2 1
7 1 5 6 3 4 8 2
----- explanation 1 ------ 
Test case 1: There is only one permutation $P = [1]$ of length $1$. Since $P_{1} = 1$ the answer does not exist.

Test case 2: Consider the permutation $P = [2, 1]$. Both conditions are satisfied.
* $P_{1} \neq 1$ and $P_{2} \neq 2$
* $|P_{1} - 1| \oplus |P_{2} - 2| = |2 - 1| \oplus |1 - 2| = 1 \oplus 1 = 0$

Test case 3: Both conditions are satisfied for $P = [7, 1, 5, 6, 3, 4, 8, 2]$.

Difficulty: MEDIUM_HARD
Tags: Bit manipulation

Mathematics

Constructive algorithms
Skill types: Bit manipulation

Starter code:

Solutions:
for i in range(int(input())):
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
	elif n == 2:
		print(2, 1)
	else:
		a = []
		if n % 2 == 0:
			for k in range(1, n + 1):
				a.append(k)
			for k in range(0, n, 2):
				q = a[k]
				a[k] = a[k + 1]
				a[k + 1] = q
			print(*a)
		else:
			a = [3, 4, 1, 5, 2]
			if n > 5:
				for k in range(6, n + 1):
					a.append(k)
				for k in range(5, n, 2):
					q = a[k]
					a[k] = a[k + 1]
					a[k + 1] = q
			print(*a)


t = int(input())
for _ in range(t):
	n = int(input())
	if n % 2 == 1:
		if n < 5:
			print(-1)
		else:
			ans5 = [4, 5, 2, 1, 3]
			ansRest = list(range(n, 5, -1))
			print(*ans5, *ansRest)
	else:
		print(*list(range(n, 0, -1)))


for _ in range(int(input())):
	n = int(input())
	if n % 2 == 1:
		if n <= 3:
			print(-1)
		else:
			temp = [n, n - 1 - 3, n - 1]
			arr = []
			for i in range(1, n - 2, 2):
				if i == temp[1]:
					arr.append(i + 1)
					arr.append(i + 2)
				else:
					arr.append(i + 1)
					arr.append(i)
			print(*arr + temp)
	else:
		ans = []
		for i in range(1, n + 1, 2):
			ans.append(i + 1)
			ans.append(i)
		print(*ans)


for i in range(int(input())):
	N = int(input())
	if N == 1 or N == 3:
		print(-1)
	else:
		nums = [i + 1 for i in range(N)]
		if N % 2 == 0:
			print(*nums[::-1])
		else:
			temp = [2, 5, 1, 3, 4]
			for i in range(6, N, 2):
				(nums[i - 1], nums[i]) = (nums[i], nums[i - 1])
			final = temp + nums[5:]
			print(*final)


t = int(input())
for i in range(t):
	n = int(input())
	if n == 1 or n == 3:
		print('-1')
	elif n % 2 == 0:
		for j in range(0, n):
			print(n - j, end=' ')
		print()
	else:
		print('4 5 2 1 3', end=' ')
		x = n
		for j in range(5, n):
			print(x, end=' ')
			x = x - 1
		print()


t = int(input())
for _ in range(t):
	n = int(input())
	if n % 2:
		if n == 1 or n == 3:
			print(-1)
		else:
			print('3 5 1 2 4', end=' ')
			for i in range(n, 5, -1):
				print(i, end=' ')
			print()
	else:
		for i in range(n, 0, -1):
			print(i, end=' ')
		print()


t = int(input())
for i in range(t):
	n = int(input())
	if n == 1 or n == 3:
		print('-1')
	else:
		d = {}
		if n % 2 == 0:
			for j in range(0, n, 2):
				d[j] = j + 2
				d[j + 1] = j + 1
		else:
			d[0] = 4
			d[1] = 5
			d[2] = 2
			d[3] = 1
			d[4] = 3
			for l in range(5, n, 2):
				d[l] = l + 2
				d[l + 1] = l + 1
		for k in range(n):
			print(d[k], end=' ')
		print()


for _ in range(int(input())):
	n = int(input())
	ans = []
	if n == 1 or n == 3:
		print(-1)
		continue
	if n % 2 == 0:
		for j in range(0, n, 2):
			ans.append(j + 2)
			ans.append(j + 1)
	else:
		ans = [2, 5, 1, 3, 4]
		for j in range(5, n, 2):
			ans.append(j + 2)
			ans.append(j + 1)
	for i in ans:
		print(i, end=' ')
	print(' ')


from sys import stdin
input = stdin.readline

def answer():
	if n == 1 or n == 3:
		return [-1]
	if n & 1:
		ans = [2, 3, 5, 1, 4]
		for i in range(6, n + 1, 2):
			ans.append(i + 1)
			ans.append(i)
	else:
		(start, end) = (1, n)
		ans = [-1 for i in range(n)]
		while start < end:
			ans[start - 1] = end
			ans[end - 1] = start
			(start, end) = (start + 1, end - 1)
	return ans
for T in range(int(input())):
	n = int(input())
	print(*answer())


testCase = int(input())
while testCase > 0:
	N = int(input())
	if N == 1 or N == 3:
		print(-1, end='')
	elif N == 2:
		print('2 1', end='')
	elif N == 5:
		print('2 3 5 1 4', end='')
	elif N % 2 == 0:
		for i in range(1, N + 1, 2):
			print(i + 1, i, end=' ')
	else:
		print('2 3 5 1 4 ', end='')
		for i in range(6, N + 1, 2):
			print(i + 1, i, end=' ')
	print('')
	testCase -= 1


for _ in range(int(input())):
	n = int(input())
	if n % 2 == 0:
		for i in range(1, n, 2):
			print(i + 1, i, end=' ')
	elif n < 5:
		print(-1, end=' ')
	else:
		print('2 5 1 3 4', end=' ')
		for i in range(6, n, 2):
			print(i + 1, i, end=' ')
	print(' ')


T = int(input())
for Tc in range(T):
	n = int(input())
	if n & 1:
		if n == 1 or n == 3:
			print(-1)
		else:
			print('3 5 1 2 4', end=' ')
			for i in range(n, 5, -1):
				print(i, end=' ')
			print()
	else:
		for i in range(1, n + 1):
			print(n - i + 1, end=' ')
		print()


for _ in range(int(input())):
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
	elif n % 2 == 0:
		lst = []
		for i in range(n):
			lst.append(n - i)
		print(*lst)
	else:
		lst = [3, 5, 1, 2, 4]
		x = n - 5
		if x > 0:
			if x % 2 == 0:
				for i in range(6, n + 1):
					lst.append(i)
					if i % 2 == 1:
						(lst[-2], lst[-1]) = (lst[-1], lst[-2])
		print(*lst)


t = int(input())

def swap(l):
	i = 0
	while i < len(l):
		temp = l[i]
		l[i] = l[i + 1]
		l[i + 1] = temp
		i = i + 2
	return l
while t > 0:
	t = t - 1
	n = int(input())
	if n % 2 != 0:
		if n == 1 or n == 3:
			print(-1)
		else:
			q = [4, 3, 5, 1, 2]
			if n == 5:
				print(*q)
			else:
				sl = []
				for i in range(6, n + 1):
					sl.append(i)
				swap(sl)
				print(*q + sl)
	else:
		tab = [i for i in range(1, n + 1)]
		print(*swap(tab))


t = int(input())
for i in range(1, t + 1):
	n = int(input())
	arr = [0] * n
	b = True
	if n % 2 == 0:
		for j in range(1, n + 1):
			if j % 2 == 1:
				arr[j - 1] = j + 1
			else:
				arr[j - 1] = j - 1
	elif n == 1 or n == 3:
		print(-1)
		b = False
	else:
		arr[0] = 3
		arr[1] = 5
		arr[2] = 1
		arr[3] = 2
		arr[4] = 4
		if n > 5:
			for j in range(6, n + 1):
				if j % 2 == 0:
					arr[j - 1] = j + 1
				else:
					arr[j - 1] = j - 1
	if b:
		print(*arr)


t = int(input())
for i in range(1, t + 1):
	n = int(input())
	arr = [0] * n
	if n % 2 == 0:
		for j in range(1, n + 1):
			if j % 2 == 1:
				arr[j - 1] = j + 1
			else:
				arr[j - 1] = j - 1
	elif n == 1 or n == 3:
		print(-1)
	else:
		arr[0] = 3
		arr[1] = 5
		arr[2] = 1
		arr[3] = 2
		arr[4] = 4
		if n > 5:
			for j in range(6, n + 1):
				if j % 2 == 0:
					arr[j - 1] = j + 1
				else:
					arr[j - 1] = j - 1
	if n != 1 and n != 3:
		print(*arr)


T = int(input())
for _ in range(T):
	N = int(input())
	if N & 1:
		if N == 1 or N == 3:
			print(-1, end=' ')
			print('')
		else:
			print('2 5 1 3 4', end=' ')
			for i in range(6, N, 2):
				print(i + 1, i, end=' ')
			print('')
	else:
		for i in range(1, N + 1, 2):
			print(i + 1, i, end=' ')
		print('')


def solve():
	n = int(input())
	if n == 1:
		print(-1)
		return
	if n == 3:
		print(-1)
		return
	if n % 2 == 0:
		print(*[i + 1 for i in range(n)][::-1])
	else:
		ans = []
		for i in range(1, n - 4, 2):
			ans.append(i + 1)
			ans.append(i)
		ans.append(n - 3)
		ans.append(n - 2)
		ans.append(n)
		ans.append(n - 4)
		ans.append(n - 1)
		print(*ans)
for _ in range(int(input())):
	solve()


def xor(ar):
	print('ar', ar)
	tot = 0
	for i in range(len(ar)):
		tot = tot ^ abs(i + 1 - ar[i])
	print('tot', tot)
t = int(input())
for _ in range(t):
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
		continue
	if n % 2 == 1:
		print(2, 5, 1, end=' ')
		for i in range(6, n + 1):
			print(i, end=' ')
		print(3, 4)
		continue
	if n == 2:
		print(2, 1)
		continue
	for i in range(n - 2):
		print(i + 3, end=' ')
	print(1, 2)


import sys
import math
from collections import defaultdict, Counter, deque
from bisect import *
from string import ascii_lowercase
from heapq import *

def readInts():
	x = list(map(int, sys.stdin.readline().rstrip().split()))
	return x[0] if len(x) == 1 else x

def readList(type=int):
	x = sys.stdin.readline()
	x = list(map(type, x.rstrip('\n\r').split()))
	return x

def readStr():
	x = sys.stdin.readline().rstrip('\r\n')
	return x
write = sys.stdout.write
read = sys.stdin.readline

def dist(x1, x2, y1, y2):
	return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

def mergeSort(arr, check=lambda a, b: a < b, reverse=False):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L, check, reverse)
		mergeSort(R, check, reverse)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if check(L[i], R[j]):
				if not reverse:
					arr[k] = L[i]
					i += 1
				else:
					arr[k] = R[j]
					j += 1
			elif not reverse:
				arr[k] = R[j]
				j += 1
			else:
				arr[k] = L[i]
				i += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1

def maxSum(arr):
	max_sum = float('-inf')
	max_cur = 0
	for num in ar:
		max_cur = max(max_cur + num, num)
		if max_cur > max_sum:
			max_sum = max_cur
	return max_sum

def hcf(a, b):
	if b == 0:
		return a
	else:
		return hcf(b, b % a)

def get_power(n, m):
	i = 1
	p = -1
	while i <= n:
		i = i * m
		p += 1
	return p

def fact(n):
	f = 1
	for i in range(2, n + 1):
		f *= i
	return f

def solve(t):
	n = readInts()
	if n & 1:
		if n < 4:
			print(-1)
		else:
			res = [4, 1, 5, 2, 3]
			for i in range(6, n + 1):
				if i & 1:
					res.append(i - 1)
				else:
					res.append(i + 1)
			print(*res)
	else:
		print(*[n - x for x in range(n)])

def main():
	sys.setrecursionlimit(12000)
	t = readInts()
	for i in range(t):
		solve(i + 1)
main()


t = int(input())
while t > 0:
	n = int(input())
	p = []
	for i in range(1, n + 1):
		p.append(i)
	if n % 2 == 0:
		for i in range(0, n, 2):
			(p[i], p[i + 1]) = (p[i + 1], p[i])
		for i in range(0, n):
			print(p[i], end=' ')
		print()
	elif n < 5:
		print('-1')
	else:
		p[0] = 4
		p[1] = 5
		p[2] = 2
		p[3] = 1
		p[4] = 3
		for i in range(5, n, 2):
			(p[i], p[i + 1]) = (p[i + 1], p[i])
		for i in range(0, n):
			print(p[i], end=' ')
		print()
	t = t - 1


def solve():
	n = int(input())
	a = list(range(1, n + 1))
	if n % 2 == 0:
		i = 0
		while i < n - 1:
			t = a[i]
			a[i] = a[i + 1]
			a[i + 1] = t
			i += 2
		print(*a)
	elif n < 5:
		print('-1')
	else:
		a[0] = 2
		a[1] = 3
		a[2] = 5
		a[3] = 1
		a[4] = 4
		i = 5
		while i < n - 1:
			t = a[i]
			a[i] = a[i + 1]
			a[i + 1] = t
			i += 2
		print(*a)
t = int(input())
for j in range(t):
	solve()


for i in range(int(input())):
	n = int(input())
	if n & 1:
		if n <= 3:
			print(-1)
		else:
			print(2, 3, 5, 1, 4, end=' ')
			for j in range(n, 5, -1):
				print(j, end=' ')
			print()
	else:
		half = n // 2
		for j in range(n // 2):
			print(half + j + 1, end=' ')
		for j in range(n // 2):
			print(j + 1, end=' ')
		print()


import collections, math, bisect, sys
from collections import OrderedDict, Counter, defaultdict
from sys import stdin, stdout

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

def in1():
	return int(stdin.readline())

def display_arr(arr):
	stdout.write(' '.join(map(str, arr)) + '\n')

def display_num(num):
	stdout.write(str(num) + '\n')

def factorial(n):
	return n * factorial(n - 1) if n > 1 else 1

def fact(n):
	n = n - 1
	return n * (n + 1) // 2

def percent(c, s):
	return c / s * 100

def l2d(a):
	return collections.Counter(a)

def lcm(x, y):
	return x * y // math.gcd(x, y)
a = []

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p]:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return set(prime)
prime = SieveOfEratosthenes(pow(10, 5))

def add(i):
	return (1 << i) - 1

def rsb(k):
	p = 1
	while k > 0:
		if k & 1:
			return p - 1
		p += 1
		k = k >> 1

def phone_number(s):
	ans = ''
	l = 0
	mul = 1
	for i in range(len(s)):
		if s[i] == ' ':
			r = i
			char = s[l:r]
			if char == 'double':
				mul = 2
			elif char == 'triple':
				mul = 3
			else:
				ans += mul * str(d[char])
				mul = 1
			l = r + 1
	ans += mul * str(d[s[l:len(s)]])
	return ans
d = [0, 0]
b = 1

def isPrime(p):
	if p == 1:
		return 0
	i = 2
	while i * i <= n:
		if n % i == 0:
			return 0
		i += 1
	return 1
d = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9, 'zero': 0}

def main():
	for _ in range(in1()):
		n = in1()
		if n == 1 or n == 3:
			print(-1)
		elif n & 1:
			res = [2, 3, 5, 1, 4]
			f = 5
			while len(res) + 2 <= n:
				res.extend([f + 2, f + 1])
				f += 2
			print(*res)
		else:
			res = []
			f = 0
			while len(res) + 2 <= n:
				res.extend([f + 2, f + 1])
				f += 2
			print(*res)
main()


for _ in range(int(input())):
	N = int(input())
	if N % 2:
		if N in [1, 3]:
			print(-1)
		else:
			outstr = '4 3 5 1 2'
			if N > 5:
				for i in range(7, N + 1, 2):
					outstr += f' {i} {i - 1}'
			print(outstr)
	else:
		outstr = f'{N}'
		a = [i for i in range(N - 1, 0, -1)]
		for i in a:
			outstr += f' {i}'
		print(outstr)


t = int(input())
for _ in range(0, t):
	n = int(input())
	if n % 2 == 1:
		if n == 1 or n == 3:
			print('-1')
		else:
			s = '4 3 5 1 2 '
			if n > 5:
				for i in range(7, n + 1, 2):
					s += str(i) + ' ' + str(i - 1) + ' '
			print(s.strip())
	else:
		s = ''
		for i in range(n // 2 + 1, n + 1):
			s += str(i) + ' '
		for i in range(1, n // 2 + 1):
			s += str(i) + ' '
		print(s.strip())


for _ in range(int(input())):
	N = int(input())
	if N % 2 == 1 and N <= 3:
		print(-1)
	elif N % 2 == 0:
		arr = [(i + 1, i) for i in range(1, N + 1, 2)]
		arr = [j for i in arr for j in i]
		print(*arr)
	else:
		arr = [2, 3, 5, 1, 4]
		arr1 = [(i + 1, i) for i in range(6, N + 1, 2)]
		arr1 = [j for i in arr1 for j in i]
		arr += arr1
		print(*arr)


from itertools import permutations
sl = []
for sl in list(permutations(range(1, 5 + 1))):
	f = 0
	for i in range(5):
		if i + 1 == sl[i]:
			f = 1
			break
	if f:
		continue
	xo = 0
	for i in range(5):
		xo ^= abs(sl[i] - (i + 1))
	if xo == 0:
		break

def swap(sidx, eidx):
	for i in range(sidx, eidx, 2):
		(l[i], l[i + 1]) = (l[i + 1], l[i])
for _ in range(int(input())):
	n = int(input())
	if n % 2 == 0:
		l = []
		for i in range(n):
			l.append(i + 1)
		swap(0, n)
		print(*l)
	elif n < 5:
		print(-1)
	else:
		l = []
		for i in range(n):
			l.append(i + 1)
		swap(5, n)
		l[0:5] = sl
		print(*l)


for _ in range(int(input())):
	N = int(input())
	l = [i for i in range(1, N + 1)]
	five = [4, 5, 1, 3, 2]
	if N == 1 or N == 3:
		print(-1)
	elif N % 2 == 0:
		l = l[::-1]
		print(*l)
	else:
		rem = l[5:]
		ans = five + rem[::-1]
		print(*ans)


def gen(s, n):
	a = range(s, n, 2)
	b = range(s + 1, n + 1, 2)
	index = n
	if s == 6:
		index = n - 5
	for i in range(index):
		if i % 2 == 0:
			print(b[i // 2], end=' ')
		else:
			print(a[i // 2], end=' ')
	print('\n')
for _ in range(int(input())):
	n = int(input())
	if n % 2 == 0:
		gen(1, n)
	elif n < 5:
		print(-1, '\n')
	else:
		print('2 3 5 1 4', end=' ')
		gen(6, n)


for t in range(int(input())):
	N = int(input())
	if N == 1 or N == 3:
		print(-1)
		continue
	if N % 2 == 0:
		print(*list(range(N, 0, -1)))
	else:
		if N == 5:
			print(*[4, 5, 2, 1, 3])
			continue
		ind = N // 2
		A = list(range(N, 0, -1))
		(A[ind], A[ind + 1]) = (A[ind + 1], A[ind])
		(A[ind + 2], A[ind + 3]) = (A[ind + 3], A[ind + 2])
		print(*A)


for _ in range(int(input())):
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
	else:
		ans = []
		len_ = 0
		p = 1
		if n & 1 == 0:
			while len_ != n:
				ans.append(p + 1)
				ans.append(p)
				p += 2
				len_ += 2
		else:
			ans = [2, 3, 5, 1, 4]
			len_ = 5
			p = 7
			while len_ != n:
				ans.append(p)
				ans.append(p - 1)
				p += 2
				len_ += 2
		print(*ans)


import math, bisect, heapq, random, sys, itertools
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline

def gprint(t, ans=''):
	print(f'Case #{t + 1}:', ans)
ints = lambda : list(map(int, input().split()))
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
p2 = [1]
for i in range(20):
	p2.append(p2[-1] * 2)
p = 10 ** 9 + 7
ANS = []
for t in range(int(input())):
	n = int(input())
	if n in [1, 3]:
		print(-1)
		continue
	if n % 2:
		arr = [3, 5, 4]
		for i in range(6, n + 1):
			arr.append(i)
		arr += [1, 2]
		print(*arr)
	else:
		arr = [n - i for i in range(n)]
		print(*arr)


def calculate(start: int, end: int):
	op = []
	t = 1
	while t != end + 1:
		if t % 2:
			op.append(start + 1)
		else:
			op.append(start - 1)
		start += 1
		t += 1
	return op
T = int(input())
for _ in range(T):
	N = int(input())
	if N % 2 == 0:
		print(' '.join(map(str, calculate(1, N))))
	elif N < 5:
		print(-1)
	else:
		print(' '.join(map(str, [2, 5, 1, 3, 4] + calculate(6, N - 5))))


for _ in range(int(input())):
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
	else:
		ans = []
		if n % 2 == 0:
			for j in range(n // 2 + 1, n + 1):
				ans.append(j)
			for j in range(1, n // 2 + 1):
				ans.append(j)
			print(*ans)
		else:
			ans = ans + [3, 5, 1, 2, 4]
			j = 6
			for k in range(j, n, 2):
				ans.append(k + 1)
				ans.append(k)
			print(*ans)


def display(l, n):
	nums = [i for i in range(l + 1, n + 1)]
	for i in range(-1, l - n - 1, -1):
		print(nums[i], end=' ')
	print()
for i in range(int(input())):
	n = int(input())
	if n % 2 == 0:
		display(0, n)
	elif n < 5:
		print('-1')
	else:
		print(4, 5, 2, 1, 3, end=' ')
		display(5, n)


t = int(input())
for i in range(t):
	n = int(input())
	if n % 2 == 1:
		step = [2, 4, 5, 1, 3]
		if n == 1 or n == 3:
			print('-1')
		elif n == 5:
			for i in step:
				print(i, end=' ')
			print()
		else:
			for i in range(6, n, 2):
				step.append(i + 1)
				step.append(i)
			for i in step:
				print(i, end=' ')
			print()
	else:
		for i in range(n, 0, -1):
			print(i, end=' ')
		print()


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdout = open('output.txt', 'w')
	sys.stdin = open('input.txt', 'r')

def solve(n):
	if n == 1 or n == 3:
		return [-1]
	if n % 2 == 0:
		x = n // 2
		return [x + i for i in range(1, x + 1)] + [i for i in range(1, x + 1)]
	res = []
	if n == 5:
		return [2, 3, 5, 1, 4]
	for i in range(1, n + 1):
		if i % 2 != 0:
			res.append(i + 1)
		else:
			res.append(i - 1)
	(res[-1], res[-2], res[-3]) = (n - 1, n - 1 - 3, n)
	res[-4] = n - 2
	return res

def main():
	sys.setrecursionlimit(10 ** 8)
	for _ in range(int(input())):
		N = int(input())
		result = solve(N)
		print(*result)
main()


t = int(input())
for z in range(t):
	n = int(input())
	if n % 2 == 1:
		if n == 1 or n == 3:
			print('-1')
		else:
			res = [3, 5, 1, 2, 4]
			if n == 5:
				print(*res)
			else:
				for i in range(n, 5, -1):
					res.append(i)
				print(*res)
	else:
		li = [int(x) for x in range(n, 0, -1)]
		print(*li)


t = int(input())
for i in range(t):
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
		continue
	if n % 2 != 0:
		print(3, 5, 1, 2, 4, end=' ')
		j = n
		while j >= 6:
			print(j, end=' ')
			j = j - 1
		print()
		continue
	for j in range(1, n + 1):
		print(n - j + 1, end=' ')
	print()


for z in range(int(input())):
	N = int(input())
	if N % 2 == 1 and N >= 5:
		for i in range(N - 5):
			if i % 2 == 1:
				print(i, end=' ')
			else:
				print(i + 2, end=' ')
		print(N - 3, N - 2, N, N - 4, N - 1)
	elif N % 2 == 0:
		for i in range(N, 0, -1):
			if i != 1:
				print(i, end=' ')
			else:
				print(i)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
		continue
	a = []
	e = 2
	o = 1
	for i in range(n):
		if i == n - 1 and n % 2 == 1:
			a.append(n)
			break
		if i % 2 == 0:
			a.append(e)
			e += 2
		else:
			a.append(o)
			o += 2
	if n % 2 == 1:
		t = a[n - 3]
		a[n - 3] = a[n - 1]
		a[n - 1] = t
		t = a[n - 2]
		a[n - 2] = a[n - 4]
		a[n - 4] = t
	for i in a:
		print(i, end=' ')
	print()


class Solution:

	def goodpermutation(self, n):
		arr = []
		if n % 2 == 0:
			for i in range(1, n + 1):
				arr.append(n + 1 - i)
		elif n == 1 or n == 3:
			return [-1]
		else:
			arr = [3, 5, 1, 2, 4]
			for i in range(n, 5, -1):
				arr.append(i)
		return arr
tc = int(input())
while tc > 0:
	n = int(input())
	Sol = Solution()
	print(*Sol.goodpermutation(n))
	tc -= 1


for i in range(int(input())):
	n = int(input())
	if n % 2:
		if n == 1 or n == 3:
			print(-1)
		else:
			a = [3, 5, 1, 2, 4]
			for i in range(n, 5, -1):
				a.append(i)
			print(*a)
	else:
		a = []
		for i in range(1, n + 1):
			a.append(n + 1 - i)
		print(*a)


for _ in range(int(input())):
	n = int(input())
	if n == 1 or n == 3:
		print(-1)
	elif n % 2 != 0:
		l = [0] * n
		l1 = [i for i in range(1, n + 1)]
		l1.remove(2)
		l1.remove(3)
		l1.remove(5)
		for i in range(n - 3):
			l[l1[i] - 1] = l1[n - 4 - i]
		l[1] = 5
		l[2] = 2
		l[4] = 3
		for i in l:
			print(i, end=' ')
		print()
	else:
		for i in range(n):
			print(n - i, end=' ')
		print()


import sys

def f(l, n, f):
	a = 0
	x = n - 1
	while a <= x:
		m = a + (x - a) // 2
		if l[m] == f:
			return m
		elif l[m] > f:
			x = m - 1
		else:
			a = m + 1
	return None
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	a = []
	if n % 2 == 0:
		for i in range(n // 2 + 1, n + 1):
			a.append(i)
		for i in range(1, n // 2 + 1):
			a.append(i)
		print(*a)
	elif n == 1:
		print(-1)
	elif n == 3:
		print(-1)
	else:
		a = []
		x = n - 5
		for i in range(x // 2 + 1, x + 1):
			a.append(i)
		for i in range(1, x // 2 + 1):
			a.append(i)
		a = a + [n - 2, n, n - 1, n - 4, n - 3]
		print(*a)


from heapq import heappop, heappush

def solve(N):
	if N <= 1:
		print(-1)
		return
	if N % 2 == 0:
		val = 0
		for i in range(N):
			print(N - i, end=' ')
		print()
		return
	else:
		if N == 3:
			print(-1)
			return
		res = [4, 3, 5]
		i = 6
		while len(res) < N - 2:
			res.append(i)
			res.append(i + 1)
			i += 2
		res.append(1)
		res.append(2)
		val = 0
		for i in range(len(res)):
			assert i + 1 != res[i]
			print(res[i], end=' ')
		print()
T = int(input())
res = []
for i in range(T):
	N = int(input())
	solve(N)


from collections import deque

def fun(n):
	if n == 1 or n == 3:
		return [-1]
	if n % 2:
		m = 5
		l = deque([3, 4, 1, 5, 2])
		for i in range((n - 4) // 2):
			l.append(2 + m)
			l.append(1 + m)
			m += 2
		return list(l)
	if n % 2 == 0:
		m = 0
		l = deque([])
		for i in range(n // 2):
			l.append(2 + m)
			l.append(1 + m)
			m += 2
		return list(l)
for t in range(int(input())):
	n = int(input())
	l = fun(n)
	print(*l)


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 3 or n == 1:
		print(-1)
		continue
	if n & 1:
		res = [0]
		for i in range(n, 0, -1):
			res.append(i)
		res[n // 2] = n // 2 + 1
		res[n // 2 + 1] = res[n // 2] + 2
		res[n // 2 + 2] = res[n // 2] - 2
		res[n // 2 - 1] = n // 2
		res[n // 2 + 3] = n // 2 + 2
		print(*res[1:])
	else:
		for i in range(n, 0, -1):
			print(i, end=' ')
		print()


def solve(a):
	if a % 2 == 0:
		for i in range(1, a + 1, 2):
			print(i + 1, i, end=' ')
	else:
		if a == 1 or a == 3:
			print(-1)
			return
		print('3 5 1 2 4', end=' ')
		for i in range(a, 5, -1):
			print(i, end=' ')
	print()
n = int(input())
for i in range(n):
	a = int(input())
	solve(a)


for _ in range(int(input())):
	terms = int(input())
	if terms == 1 or terms == 3:
		print(-1)
		continue
	elif terms % 2 == 0:
		for i in range(1, terms + 1):
			print(terms + 1 - i, end=' ')
		print()
	else:
		L = [3, 5, 1, 2, 4]
		for i in range(terms, 5, -1):
			L.append(i)
		print(*L)


for _ in range(int(input())):
	a = int(input())
	if a % 2 == 1:
		if a == 1 or a == 3:
			print(-1)
		else:
			print('3 5 1 2 4')
			for i in range(a, 5, -1):
				print(i, end=' ')
			print()
	else:
		for i in range(1, a + 1):
			print(a + 1 - i, end=' ')
		print()


import math
from collections import defaultdict
t = int(input())
while t:
	t -= 1
	n = int(input())
	if n == 1:
		print(-1)
	elif n % 2 == 0:
		k = 0
		for j in range(0, n // 2):
			print(k + 2, end=' ')
			print(k + 1, end=' ')
			k += 2
		print()
	elif n == 3:
		print(-1)
	elif n == 5:
		print(f'2 4 5 1 3')
	else:
		lis = [2, 4, 6, 1, 7, 3, 5]
		for j in lis:
			print(j, end=' ')
		y = 8
		for m in range((n - 7) // 2):
			print(y + 1, end=' ')
			print(y, end=' ')
			y += 2
		print()


from sys import stdin, stdout
from collections import Counter as co, defaultdict as dd
import math
mod = int(1000000000.0 + 7)

class node:

	def __init__(self, val, depth=0):
		self.val = val
		self.depth = depth
		self.left = None
		self.right = None

def create(root, x):
	if not root:
		return node(x)
	if root.val == x:
		return root
	elif x < root.val:
		root.left = create(root.left, x)
	else:
		root.right = create(root.right, x)
	return root

def fibcompute():
	ans = {1: [[0, 1], [1, 1]]}
	l = [1]
	i = 2
	while i <= 10 ** 18:
		ans[i] = matmul(ans[i / 2], ans[i / 2])
		l.append(i)
		i *= 2
	return [ans, l]

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

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

def inti():
	return int(stdin.readline().strip())

def stri():
	return stdin.readline().strip()

def matmul(a, b):
	return [[(a[0][0] % mod * b[0][0] % mod % mod + a[0][1] % mod * b[1][0] % mod % mod) % mod, (a[0][0] % mod * b[0][1] % mod % mod + a[0][1] % mod * b[1][1] % mod % mod) % mod], [(a[1][0] % mod * b[0][0] % mod % mod + a[1][1] % mod * b[1][0] % mod % mod) % mod, (a[1][0] % mod * b[0][1] % mod % mod + a[1][1] % mod * b[1][1] % mod % mod) % mod]]

def isprime(n):
	if n == 1:
		return 0
	c = 0
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			c = 1
			break
	if c == 0:
		return 1
	else:
		return 0

def noofdivisors(n):
	c = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if n == i ** 2:
				c += 1
			else:
				c += 2
	return c

def fibgreedy(n):
	ans = []
	s = bin(n)[2:]
	ls = len(s)
	for i in range(ls):
		if s[i] != '0':
			ans.append(2 ** (ls - i - 1) * int(s[i]))
	return ans

def sumd(n):
	ans = 0
	while n > 0:
		ans += n % 10
		n //= 10
	return ans

def solve():
	n = inti()
	ans = []
	if n % 2 == 0:
		for i in range(1, n + 1):
			ans.append(n - i + 1)
	else:
		if n == 1 or n == 3:
			print(-1)
			return
		ans += [3, 5, 1, 2, 4]
		for i in range(n, 5, -1):
			ans.append(i)
	print(*ans)
t = inti()
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	if n % 2 == 1 and n <= 3:
		print(-1)
	elif n == 5:
		print(2, 5, 1, 3, 4)
	elif n % 2 == 0:
		a = []
		for i in range(1, n + 1):
			a.append(n + 1 - i)
		print(*a)
	else:
		a = [2, 1]
		a.append(n)
		a.append(n - 2)
		a.append(n - 1)
		l = n - 3
		while l >= 3:
			a.append(l)
			l -= 1
		print(*a[::-1])


from math import *
from collections import *
import os
from io import BytesIO, IOBase
import sys
from bisect import *
from heapq import *
MOD = 1000000007

def subinp():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('op1.txt', 'w')

def subinp_1():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('op2.txt', 'w')

def binpow(a, b, m):
	a %= m
	x = 1
	while b > 0:
		if b & 1:
			x = x * a % m
		a = a * a % m
		b >>= 1
	return x

def binser(arr, l, r, x):
	while l < r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return mid

def lcm(a, b):
	return a * b // gcd(a, b)

def sod(n):
	l = list(str(n))
	s = 0
	for i in l:
		s += int(i)
	return s

def prime_factors(num):
	l = []
	if num % 2:
		l.append(2)
	while num % 2 == 0:
		num = num / 2
	for i in range(3, int(sqrt(num)) + 1, 2):
		if not num % i:
			l.append(i)
		while num % i == 0:
			num = num / i
	if num > 2:
		l.append(num)
	return l

def factmod(n, p):
	f = defaultdict(int)
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % MOD
	return f

def largestPower(n, p):
	x = 0
	while n:
		n //= p
		x += n
	return x

def modFact(n, p):
	if n >= p:
		return 0
	res = 1
	isPrime = [1] * (n + 1)
	i = 2
	while i * i <= n:
		if isPrime[i]:
			for j in range(2 * i, n, i):
				isPrime[j] = 0
		i += 1
	for i in range(2, n):
		if isPrime[i]:
			k = largestPower(n, i)
			res = res * binpow(i, k, p) % p
	return res

def drec(x, y):
	if y == x + 1:
		return 'R'
	if y == x - 1:
		return 'L'
	if x < y:
		return 'D'
	return 'U'

def cellhash(x, y):
	return (x - 1) * m + y

def bins(l, x, n):
	i = bisect_left(l, x)
	if i < n:
		return i
	if i:
		return i - 1
	else:
		return n

def cond(l):
	for i in range(len(l) - 1):
		if l[i] == str(int(l[i + 1]) - 1):
			return False
	return True

def isvowel(s):
	if s in list('aeiou'):
		return 1
	return 0

def countOdd(L, R):
	N = (R - L) // 2
	if R % 2 != 0 or L % 2 != 0:
		N += 1
	return N

def tst(A, B, C):
	return (A | B) & (B | C) & (C | A)

def palcheck(n, s):
	(i, j) = (0, n - 1)
	while i <= j:
		if s[i] == s[j]:
			return False
		i += 1
		j -= 1
	return True

def sakurajima(n):
	if n < 9:
		n = 10
	l = [0]
	for i in range(1, n + 1):
		if i % 2:
			l.append(i)
		else:
			l.append(2)
	for i in range(3, int(n ** 0.5) + 1, 2):
		if l[i] == i:
			for j in range(i * i, n + 1, i):
				if l[j] == j:
					l[j] = i
	return l

def getfact(x):
	ret = []
	d = defaultdict(int)
	while x != 1:
		ret.append(spf[x] ** (d[spf[x]] + 1))
		d[spf[x]] += 1
		x = x // spf[x]
	return ret

def prchck(n):
	l = [1] * (n + 1)
	l[1] = 0
	for i in range(2, n + 1):
		for j in range(2, int(sqrt(n)) + 1):
			if j % i == 0:
				l[j] = 1
	return l

def ispal(s, n):
	for i in range(n // 2):
		if s[i] != s[n - i - 1]:
			return False
	return True

def bfs(src, dest, ajl, vis):
	q = deque([src])
	vis[src] = True
	while q:
		i = q.popleft()
		if i == dest:
			return True
		for j in ajl[i]:
			if not vis[j]:
				vis[j] = True
				q.append(j)
	return False

def sieve(n):
	if n < 9:
		n = 10
	l = [1] * (n + 1)
	for i in range(2, int(n ** 0.5) + 1):
		if l[i]:
			for j in range(i ** 2, n + 1, i):
				if j % i == 0:
					l[j] = 0
	l[1] = 0
	return l

class DisjSet:

	def __init__(self, n):
		self.size = [1] * n
		self.parent = [i for i in range(n)]

	def find(self, x):
		if self.parent[x] != x:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, x, y):
		xset = self.find(x)
		yset = self.find(y)
		if xset == yset:
			return
		if self.size[xset] < self.size[yset]:
			self.parent[xset] = yset
			self.size[yset] += self.size[xset]
		else:
			self.parent[yset] = xset
			self.size[xset] += self.size[yset]

def dfs(i, ajl, vis, l, x):
	vis[i] = True
	l[i] = x
	for j in ajl[i]:
		if not vis[j]:
			dfs(j, ajl, vis, l, x)

def checkpo3(N):
	while N > 0:
		if N % 3 == 2:
			return False
		N //= 3
	return True

def sumofdig(n):
	ans = 0
	s = str(n)
	for i in s:
		ans += int(i)
	return ans

def convert(set):
	return [*set]
inp = lambda : int(input())
strin = lambda : input().strip()
strl = lambda : list(input().strip())
strlst = lambda : list(map(str, input().split()))
mult = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
lstin = lambda : list(map(int, input().strip().split()))
flush = lambda : stdout.flush()
stdpr = lambda x: stdout.write(str(x))

def panda(n):
	ans = []
	if n == 1 or n == 3:
		return [-1]
	if n % 2:
		ans = [3, 5, 1, 2, 4]
		for i in range(n, 5, -1):
			ans.append(i)
		return ans
	for i in range(n, 0, -1):
		ans.append(i)
	return ans
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = 1
t = int(input())
for _ in range(t):
	n = inp()
	ans = panda(n)
	print(*ans)


import math
import bisect
import heapq
from math import gcd, floor, sqrt, log
from collections import defaultdict as ddc
from collections import Counter

def intin():
	return int(input())

def mapin():
	return map(int, input().split())

def strin():
	return input().split()
INF = 10 ** 20
mod = 1000000007

def exponentiation(bas, exp, mod=1000000007):
	t = 1
	while exp > 0:
		if exp % 2 != 0:
			t = t * bas % mod
		bas = bas * bas % mod
		exp //= 2
	return t % mod

def MOD(p, q=1, mod=1000000007):
	expo = 0
	expo = mod - 2
	while expo:
		if expo & 1:
			p = p * q % mod
		q = q * q % mod
		expo >>= 1
	return p

def process(N):
	if N in [1, 3]:
		return [-1]
	ans = []
	if not N % 2:
		for i in range(1, N + 1, 2):
			ans.append(i + 1)
			ans.append(i)
	else:
		ans = [2, 3, 5, 1, 4]
		for i in range(6, N + 1, 2):
			ans.append(i + 1)
			ans.append(i)
	return ans

def main():
	for _ in range(int(input())):
		N = intin()
		print(*process(N))
main()


def ispo(n):
	if n == 1 or n == 3:
		print(-1)
	elif n % 2 == 1:
		for i in range(3, n):
			print(i, end=' ')
		print(1, n, 2)
	else:
		for i in range(n, 0, -1):
			print(i, end=' ')
		print()
for _ in range(int(input())):
	ispo(int(input()))


for z in range(int(input())):
	n = int(input())
	if n % 2 == 1:
		if n == 1 or n == 3:
			print('-1')
		else:
			s = '3 5 1 2 4 '
			print(s)
			for i in range(n, 5, -1):
				print(i, end=' ')
	else:
		for i in range(1, n + 1):
			print(n + 1 - i, end=' ')
		print()