You are given an array $a$ consisting of $n$ integers (it is guaranteed that $n$ is even, i.e. divisible by $2$). All $a_i$ does not exceed some integer $k$.

Your task is to replace the minimum number of elements (replacement is the following operation: choose some index $i$ from $1$ to $n$ and replace $a_i$ with some integer in range $[1; k]$) to satisfy the following conditions:  after all replacements, all $a_i$ are positive integers not greater than $k$;  for all $i$ from $1$ to $\frac{n}{2}$ the following equation is true: $a_i + a_{n - i + 1} = x$, where $x$ should be the same for all $\frac{n}{2}$ pairs of elements. 

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains two integers $n$ and $k$ ($2 \le n \le 2 \cdot 10^5, 1 \le k \le 2 \cdot 10^5$) — the length of $a$ and the maximum possible value of some $a_i$ correspondingly. It is guratanteed that $n$ is even (i.e. divisible by $2$). The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the $i$-th element of $a$.

It is guaranteed that the sum of $n$ (as well as the sum of $k$) over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$, $\sum k \le 2 \cdot 10^5$).


-----Output-----

For each test case, print the answer — the minimum number of elements you have to replace in $a$ to satisfy the conditions from the problem statement.


-----Example-----
Input
4
4 2
1 2 1 2
4 3
1 2 2 1
8 7
6 1 1 7 6 3 4 6
6 6
5 2 6 1 3 4

Output
0
1
4
2

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Complete search

Data structures

Amortized analysis

Greedy algorithms


Solutions:
import bisect

def main():
	t = int(input())
	for _ in range(t):
		line = input().split()
		(n, k) = (int(line[0]), int(line[1]))
		nums = list(map(int, input().split()))
		dic = {}
		min_ = []
		max_ = []
		for i in range(n // 2):
			dic[nums[i] + nums[n - i - 1]] = dic.get(nums[i] + nums[n - i - 1], 0) + 1
			min_.append(min(nums[i], nums[n - i - 1]))
			max_.append(max(nums[i], nums[n - i - 1]))
		min_.sort()
		max_.sort()
		m = len(min_)
		ans = m
		for key in dic:
			res = 0
			left = bisect.bisect_left(max_, key - k)
			res += left * 2
			right = bisect.bisect_right(min_, key - 1)
			res += (m - right) * 2
			res += m - left - (m - right) - dic[key]
			ans = min(ans, res)
		print(ans)
main()


from collections import defaultdict
import sys
stream = sys.stdin
t = int(stream.readline())
for line in stream:
	(n, k) = line.split()
	(n, k) = map(int, (n, k))
	sums_rating = defaultdict(int)
	open_close = defaultdict(int)
	numbers = stream.readline().split()
	for i in range(n // 2):
		n1 = int(numbers[i])
		n2 = int(numbers[-(i + 1)])
		sums_rating[n1 + n2] += 1
		mini = min(n1, n2)
		maxi = max(n1, n2)
		open_close[mini + 1] += 1
		open_close[maxi + k + 1] -= 1
	curr_modifier = 0
	best_result = -float('inf')
	for i in range(2, 2 * k + 1):
		curr_modifier += open_close[i]
		if sums_rating[i] + curr_modifier > best_result:
			best_result = sums_rating[i] + curr_modifier
	print(n - best_result)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	count0 = [0] * (2 * k + 1)
	pre_arr = [0] * (2 * k + 2)
	for i in range(n // 2):
		p1 = arr[i]
		p2 = arr[n - i - 1]
		l = min(p1, p2) + 1
		r = max(p1, p2) + k
		count0[p1 + p2] += 1
		pre_arr[l] += 1
		pre_arr[r + 1] -= 1
	for i in range(1, 2 * k + 2):
		pre_arr[i] += pre_arr[i - 1]
	ans = float('INF')
	for i in range(2, 2 * k + 1):
		c0 = count0[i]
		c1 = pre_arr[i] - c0
		c2 = n // 2 - c0 - c1
		ans = min(ans, c1 + 2 * c2)
	print(ans)


import string
from collections import defaultdict, Counter
from math import sqrt, log10, log2, log, gcd, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from itertools import combinations, combinations_with_replacement
import sys, io, os
sys.setrecursionlimit(10000)
mod = 10 ** 9 + 7
inf = float('inf')

def get_list():
	return [int(i) for i in input().split()]

def yn(a):
	print('YES' if a else 'NO', flush=False)
t = 1
t = int(input())
for i in range(t):
	(n, k) = get_list()
	l = get_list()
	pre = [0] * (2 * k + 2)
	for iter1 in range(n):
		iter2 = n - 1 - iter1
		pre[2] += 2
		pre[2 * k + 1] -= 2
		mina = min(1 + l[iter1], 1 + l[iter2])
		maxa = max(k + l[iter1], k + l[iter2])
		pre[mina] -= 1
		pre[maxa + 1] += 1
		pre[l[iter1] + l[iter2]] -= 1
		pre[l[iter1] + l[iter2] + 1] += 1
	for i in range(1, len(pre)):
		pre[i] += pre[i - 1]
	print(min(pre[2:2 * k + 1]) // 2)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	c = [n] + [0] * (k * 2)
	for i in range(n // 2):
		(x, y) = sorted((a[i], a[-(i + 1)]))
		c[x] -= 1
		c[x + y - 1] -= 1
		c[x + y] += 1
		c[k + y] += 1
	for i in range(k * 2):
		c[i + 1] += c[i]
	print(min(c))


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		(n, k) = ria()
		a = ria()
		a1 = a[:n // 2]
		a2 = a[n // 2:][::-1]
		z = []
		pref = [0] * (2 * k + 5)
		for i in range(n // 2):
			z.append([min(a1[i], a2[i]), max(a1[i], a2[i])])
		for i in z:
			(l, r) = i
			L = 2
			R = 1 + l - 1
			if R >= L:
				pref[L] += 2
				pref[R + 1] -= 2
			L = 1 + l
			R = l + r - 1
			if R >= L:
				pref[L] += 1
				pref[R + 1] -= 1
			L = l + r + 1
			R = r + k
			if R >= L:
				pref[L] += 1
				pref[R + 1] -= 1
			L = r + k + 1
			R = 2 * k
			if R >= L:
				pref[L] += 2
				pref[R + 1] -= 2
		for i in range(1, len(pref)):
			pref[i] += pref[i - 1]
		ans = 999999999999999999
		for i in range(2, 2 * k + 1):
			ans = min(ans, pref[i])
		print(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


t = int(input())
cnt = 0
while cnt < t:
	cnt += 1
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	c = []
	for i in range(n // 2):
		c.append((min(a[i] + 1, a[n - i - 1] + 1), -1))
		c.append((max(a[i] + k, a[n - i - 1] + k) + 1, 1))
	for i in range(n // 2):
		c.append((a[i] + a[n - i - 1], -1))
		c.append((a[i] + a[n - i - 1] + 1, 1))
	d = {}
	for i in range(len(c)):
		d[c[i][0]] = d.get(c[i][0], 0) + c[i][1]
	counter = n
	val_res = n
	for (key, val) in sorted(list(d.items())):
		counter += val
		if val_res > counter:
			val_res = counter
	print(val_res)


from collections import Counter
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		(n, k) = MI()
		aa = LI()
		cnt = [0] * (2 * k + 2)
		for i in range(n // 2):
			(a, b) = (aa[i], aa[n - 1 - i])
			if a > b:
				(a, b) = (b, a)
			cnt[0] += 2
			cnt[a + 1] += -1
			cnt[a + b] += -1
			cnt[a + b + 1] += 1
			cnt[b + k + 1] += 1
		for i in range(2 * k + 1):
			cnt[i + 1] += cnt[i]
		print(min(cnt))
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cost = [0 for i in range(2 * k + 2)]
	d = [0 for i in range(2 * k + 2)]
	mn = 10 ** 9
	h = 0
	now_cost = 0
	m = {i: 0 for i in range(2, 2 * k + 1)}
	for i in range(n // 2):
		b = a[i] + a[n - 1 - i]
		m[b] += 1
		d[1 + min(a[i], a[n - 1 - i])] += 1
		d[k + max(a[i], a[n - 1 - i]) + 1] -= 1
		cost[k + max(a[i], a[n - 1 - i]) + 1] -= 1
		cost[1 + min(a[i], a[n - i - 1])] += 1
	h = 0
	for i in range(2, 2 * k + 1):
		h += d[i]
		now_cost += cost[i]
		mn = min(mn, now_cost + 2 * (n // 2 - h) - m[i])
	print(mn)


class BIT:

	def __init__(self, n):
		self.n = n
		self.bit = [0] * (n + 1)

	def _add(self, i, val):
		while i > 0:
			self.bit[i] += val
			i -= i & -i

	def get_val(self, i):
		i = i + 1
		s = 0
		while i <= self.n:
			s += self.bit[i]
			i += i & -i
		return s

	def add(self, l, r, val):
		self._add(r, val)
		self._add(l, -val)
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = a[n // 2:n][::-1]
	a = a[0:n // 2]
	bit = BIT(2 * k + 1)
	bit.add(0, 2 * k + 1, 2 * n // 2)
	for i in range(n // 2):
		ran = [min(a[i] + 1, b[i] + 1), max(a[i] + k + 1, b[i] + k + 1)]
		bit.add(ran[0], ran[1], -1)
		bit.add(a[i] + b[i], a[i] + b[i] + 1, -1)
	print(min([bit.get_val(i) for i in range(2 * k + 1)]))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	price = [0] * (2 * k + 5)
	for i in range(n // 2):
		price[2] += 2
		s = min(a[i], a[n - i - 1])
		l = max(a[i], a[n - i - 1])
		price[s + 1] -= 1
		price[s + l] -= 1
		price[s + l + 1] += 1
		price[l + k + 1] += 1
	sum = 0
	maxi = 1000000000000.0
	for i in price[2:2 * k + 2]:
		sum += i
		maxi = min(maxi, sum)
	print(maxi)


def search(cumurange, target, lwr=0, upr=False):
	if not upr:
		upr = len(cumurange) - 1
	if upr - lwr == 1:
		if cumurange[upr][0] < target:
			return cumurange[upr]
		else:
			return cumurange[lwr]
	avg = (upr + lwr) // 2
	test = cumurange[avg]
	if test[0] > target:
		return search(cumurange, target, lwr, avg)
	else:
		return search(cumurange, target, avg, upr)
T = int(input())
for test in range(T):
	(N, K) = list(map(int, input().split()))
	array = list(map(int, input().split()))
	totalpairs = N // 2
	pairsum = {}
	exceed2 = 0
	exceed1 = 0
	bounds = {}
	for n in range(totalpairs):
		a1 = array[n]
		a2 = array[N - 1 - n]
		sm = a1 + a2
		if a1 > K and a2 > K:
			exceed2 += 1
			continue
		elif a1 > K or a2 > K:
			a = min(a1, a2)
			minsum = a + 1
			maxsum = a + K + 1
		else:
			minsum = min(a1, a2) + 1
			maxsum = max(a1, a2) + K + 1
			asum = a1 + a2
			if asum in pairsum.keys():
				pairsum[asum] += 1
			else:
				pairsum[asum] = 1
		if minsum in bounds.keys():
			bounds[minsum] += 1
		else:
			bounds[minsum] = 1
		if maxsum in bounds.keys():
			bounds[maxsum] -= 1
		else:
			bounds[maxsum] = -1
	boundorder = sorted(bounds.items(), key=lambda x: x[0])
	cumulativerange = [boundorder[0]]
	for n in range(1, len(boundorder)):
		(pos, qty) = boundorder[n]
		prevqty = cumulativerange[n - 1][1]
		cumulativerange.append((pos, qty + prevqty))
	pairsum = list(pairsum.items())
	changes = []
	for cumu in cumulativerange:
		changes.append(N - cumu[1])
	for pair in pairsum:
		(pos, val) = pair
		cumu = search(cumulativerange, pos)
		changes.append(N - cumu[1] - val)
	minchanges = min(changes)
	print(minchanges)


import os
from collections import defaultdict

def f(nums, k):
	n = len(nums)
	n2 = n // 2
	p = defaultdict(int, {})
	mi = defaultdict(int, {})
	ma = defaultdict(int, {})
	for i in range(n2):
		p[nums[i] + nums[n - i - 1]] += 1
		mi[min(nums[i], nums[n - i - 1])] += 1
		ma[max(nums[i], nums[n - i - 1])] += 1
	mlx = 0
	mgx = 0
	cost = n
	for x in range(2 * k + 1):
		mlx += mi[x - 1]
		mgx += ma[x - k - 1]
		cost = min(n - mlx - p[x] + mgx, cost)
	return cost

def pp(input):
	n_test = int(input())
	for i in range(n_test):
		k = int(input().split()[1])
		print(f(list(map(int, input().split())), k))
if 'paalto' in os.getcwd():
	from string_source import string_source
	s = string_source('4\n4 2\n1 2 1 2\n4 3\n1 2 2 1\n8 7\n6 1 1 7 6 3 4 6\n6 6\n5 2 6 1 3 4')
	pp(s)
else:
	pp(input)


t = int(input())
while t:
	(n, k) = map(int, input().split())
	li = list(map(int, input().split()))
	one_counts = [0] * (2 * k + 5)
	pairs_array = []
	for i in range(len(li) // 2):
		pairs_array.append([min(li[i], li[n - i - 1]), max(li[i], li[n - i - 1])])
	zero_counts = {}
	for pair in pairs_array:
		lower_bound = pair[0] + 1
		upper_bound = pair[1] + k
		if not zero_counts.get(pair[0] + pair[1]):
			zero_counts[pair[0] + pair[1]] = 1
		else:
			zero_counts[pair[0] + pair[1]] += 1
		one_counts[lower_bound] += 1
		one_counts[upper_bound + 1] -= 1
	for i in range(1, len(one_counts)):
		one_counts[i] = one_counts[i] + one_counts[i - 1]
	min_nums = n
	for i in range(2, 2 * k + 1):
		total_sum = i
		zero_changes = 0
		if zero_counts.get(i):
			zero_changes = zero_counts[i]
		one_changes = one_counts[i] - zero_changes
		two_changes = n // 2 - one_changes - zero_changes
		min_nums = min(one_changes + two_changes * 2, min_nums)
	print(min_nums)
	t -= 1


import math
from decimal import *
getcontext().prec = 30
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	l = [0] * (2 * k + 2)
	for i in range(n // 2):
		l[1] += 2
		l[2 * k + 1] -= 2
		mini = min(a[i], a[n - 1 - i]) + 1
		maxi = max(a[i], a[n - 1 - i]) + k
		sum = a[i] + a[n - 1 - i]
		l[mini] += -1
		l[maxi + 1] += 1
		l[sum] += -1
		l[sum + 1] += 1
	ans = 10 ** 10
	for i in range(2, 2 * k + 1):
		l[i] += l[i - 1]
		ans = min(ans, l[i])
	print(ans)


from functools import cmp_to_key
from collections import deque
from heapq import heappush, heappop
from math import log, ceil
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def ii():
	return int(inp())

def li(lag=0):
	l = list(map(int, inp().split()))
	if lag != 0:
		for i in range(len(l)):
			l[i] += lag
	return l

def mi(lag=0):
	matrix = list()
	for i in range(n):
		matrix.append(li(lag))
	return matrix

def sli():
	return list(map(str, inp().split()))

def print_list(lista, space=' '):
	print(space.join(map(str, lista)))

class UnionFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def bisect_left(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] < x:
			left = mid + 1
		else:
			right = mid
	return left

def bisect_right(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] > x:
			right = mid
		else:
			left = mid + 1
	return left

def bisect_elements(a, x):
	return bisect_right(a, x) - bisect_left(a, x)

def custom_sort(lista):

	def cmp(x, y):
		if x + y > y + x:
			return 1
		else:
			return -1
	return sorted(lista, key=cmp_to_key(cmp))
MOD = 10 ** 9 + 7
maxN = 10 ** 5
FACT = [0] * maxN

def add(x, y):
	return (x + y) % MOD

def multiply(x, y):
	return x * y % MOD

def power(x, y):
	if y == 0:
		return 1
	elif y % 2:
		return multiply(x, power(x, y - 1))
	else:
		a = power(x, y // 2)
		return multiply(a, a)

def inverse(x):
	return power(x, MOD - 2)

def divide(x, y):
	return multiply(x, inverse(y))

def allFactorials():
	FACT[0] = 1
	for i in range(1, maxN):
		FACT[i] = multiply(i, FACT[i - 1])

def coeffBinom(n, k):
	if n < k:
		return 0
	return divide(FACT[n], multiply(FACT[k], FACT[n - k]))

def primes(N):
	smallest_prime = [1] * (N + 1)
	prime = []
	smallest_prime[0] = 0
	smallest_prime[1] = 0
	for i in range(2, N + 1):
		if smallest_prime[i] == 1:
			prime.append(i)
			smallest_prime[i] = i
		j = 0
		while j < len(prime) and i * prime[j] <= N:
			smallest_prime[i * prime[j]] = min(prime[j], smallest_prime[i])
			j += 1
	return (prime, smallest_prime)

def gcd(a, b):
	a = abs(a)
	b = abs(b)
	(s, t, r) = (0, 1, b)
	(old_s, old_t, old_r) = (1, 0, a)
	while r != 0:
		quotient = old_r // r
		(old_r, r) = (r, old_r - quotient * r)
		(old_s, s) = (s, old_s - quotient * s)
		(old_t, t) = (t, old_t - quotient * t)
	return (old_r, old_s, old_t)

def create_graph(n, m, undirected=1, unweighted=1):
	graph = [[] for i in range(n)]
	if unweighted:
		for i in range(m):
			[x, y] = li(lag=-1)
			graph[x].append(y)
			if undirected:
				graph[y].append(x)
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			graph[x].append([y, w])
			if undirected:
				graph[y].append([x, w])
	return graph

def create_tree(n, unweighted=1):
	children = [[] for i in range(n)]
	if unweighted:
		for i in range(n - 1):
			[x, y] = li(lag=-1)
			children[x].append(y)
			children[y].append(x)
	else:
		for i in range(n - 1):
			[x, y, w] = li(lag=-1)
			w += 1
			children[x].append([y, w])
			children[y].append([x, w])
	return children

def create_edges(m, unweighted=0):
	edges = list()
	if unweighted:
		for i in range(m):
			edges.append(li(lag=-1))
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			edges.append([w, x, y])
	return edges

def dist(tree, n, A, B=-1):
	s = [[A, 0]]
	(massimo, massimo_nodo) = (0, 0)
	distanza = -1
	v = [-1] * n
	while s:
		(el, dis) = s.pop()
		if dis > massimo:
			massimo = dis
			massimo_nodo = el
		if el == B:
			distanza = dis
		for child in tree[el]:
			if v[child] == -1:
				v[child] = 1
				s.append([child, dis + 1])
	return (massimo, massimo_nodo, distanza)

def diameter(tree):
	(_, foglia, _) = dist(tree, n, 0)
	(diam, _, _) = dist(tree, n, foglia)
	return diam

def dfs(graph, n, A):
	v = [-1] * n
	s = [[A, 0]]
	v[A] = 0
	while s:
		(el, dis) = s.pop()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def bfs(graph, n, A):
	v = [-1] * n
	s = deque()
	s.append([A, 0])
	v[A] = 0
	while s:
		(el, dis) = s.popleft()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def connected(graph, n):
	v = dfs(graph, n, 0)
	for el in v:
		if el == -1:
			return False
	return True

def topological(graph, n):
	indegree = [0] * n
	for el in range(n):
		for child in graph[el]:
			indegree[child] += 1
	s = deque()
	for el in range(n):
		if indegree[el] == 0:
			s.append(el)
	order = []
	while s:
		el = s.popleft()
		order.append(el)
		for child in graph[el]:
			indegree[child] -= 1
			if indegree[child] == 0:
				s.append(child)
	if n == len(order):
		return (False, order)
	else:
		return (True, [])

def bipartite(graph, n):
	color = [-1] * n
	color[0] = 0
	s = [0]
	while s:
		el = s.pop()
		for child in graph[el]:
			if color[child] == color[el]:
				return False
			if color[child] == -1:
				s.append(child)
			color[child] = 1 - color[el]
	return True

def dijkstra(graph, n, A):
	dist = [float('inf') for i in range(n)]
	prev = [-1 for i in range(n)]
	dist[A] = 0
	pq = []
	heappush(pq, [0, A])
	while pq:
		[d_v, v] = heappop(pq)
		if d_v != dist[v]:
			continue
		for (to, w) in graph[v]:
			if dist[v] + w < dist[to]:
				dist[to] = dist[v] + w
				prev[to] = v
				heappush(pq, [dist[to], to])
	return (dist, prev)

def dijkstra_0_1(graph, n, A):
	dist = [float('inf') for i in range(n)]
	dist[A] = 0
	p = deque()
	p.append(A)
	while p:
		v = p.popleft()
		for (to, w) in graph[v]:
			if dist[v] + w < dist[to]:
				dist[to] = dist[v] + w
			if w == 1:
				q.append(to)
			else:
				q.appendleft(to)
	return dist

def floyd_warshall(graph, n):
	dist = [[float('inf') for _ in range(n)] for _ in range(n)]
	for i in range(n):
		dist[i][i] = 0
		for (child, d) in graph[i]:
			dist[i][child] = d
			dist[child][i] = d
	for k in range(n):
		for i in range(n):
			for j in range(j):
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
	return dist

def minimum_spanning_tree(edges, n):
	edges = sorted(edges)
	union_find = UnionFind(n)
	used_edges = list()
	for (w, x, y) in edges:
		if union_find.find(x) != union_find.find(y):
			union_find.merge(x, y)
			used_edges.append([w, x, y])
	return used_edges

def parents_children_root_unrooted_tree(tree, n, root=0):
	q = deque()
	visited = [0] * n
	parent = [-1] * n
	children = [[] for i in range(n)]
	q.append(root)
	while q:
		all_done = 1
		visited[q[0]] = 1
		for child in tree[q[0]]:
			if not visited[child]:
				all_done = 0
				q.appendleft(child)
		if all_done:
			for child in tree[q[0]]:
				if parent[child] == -1:
					parent[q[0]] = child
					children[child].append(q[0])
			q.popleft()
	return (parent, children)

def all_longest_path_passing_from_node(parent, children, n):
	q = deque()
	visited = [len(children[i]) for i in range(n)]
	downwards = [[0, 0] for i in range(n)]
	upward = [1] * n
	longest_path = [1] * n
	for i in range(n):
		if not visited[i]:
			q.append(i)
			downwards[i] = [1, 0]
	while q:
		node = q.popleft()
		if parent[node] != -1:
			visited[parent[node]] -= 1
			if not visited[parent[node]]:
				q.append(parent[node])
		else:
			root = node
		for child in children[node]:
			downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse=True)[0:2]
	s = [node]
	while s:
		node = s.pop()
		if parent[node] != -1:
			if downwards[parent[node]][0] == downwards[node][0] + 1:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1])
			else:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0])
		longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1
		for child in children[node]:
			s.append(child)
	return longest_path

def finding_ancestors(parent, queries, n):
	steps = int(ceil(log(n, 2)))
	ancestors = [[-1 for i in range(n)] for j in range(steps)]
	ancestors[0] = parent
	for i in range(1, steps):
		for node in range(n):
			if ancestors[i - 1][node] != -1:
				ancestors[i][node] = ancestors[i - 1][ancestors[i - 1][node]]
	result = []
	for (node, k) in queries:
		ans = node
		if k >= n:
			ans = -1
		i = 0
		while k > 0 and ans != -1:
			if k % 2:
				ans = ancestors[i][ans]
			k = k // 2
			i += 1
		result.append(ans)
	return result

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def nearest_from_the_left_smaller_elements(arr):
	n = len(arr)
	res = [-1] * n
	s = []
	for (i, el) in enumerate(arr):
		while s and s[-1] >= el:
			s.pop()
		if s:
			res[i] = s[-1]
		s.append(el)
	return res

def sliding_window_minimum(arr, k):
	res = []
	q = deque()
	for (i, el) in enumerate(arr):
		while q and arr[q[-1]] >= el:
			q.pop()
		q.append(i)
		while q and q[0] <= i - k:
			q.popleft()
		if i >= k - 1:
			res.append(arr[q[0]])
	return res
for test in range(ii()):
	[n, k] = li()
	a = li()
	first = list()
	second = list()
	ma = [0 for i in range(k + 4)]
	somme = [0 for i in range(2 * k + 1)]
	for i in range(n // 2):
		a1 = a[i]
		a2 = a[n - i - 1]
		m = max(a1, a2)
		ma[m] += 1
		somme[a1 + a2] += 1
		first.append(a1)
		second.append(a2)
	first = sorted(first)
	second = sorted(second)
	pre = [0 for i in range(k + 4)]
	for i in range(1, k + 4):
		pre[i] = pre[i - 1] + ma[i]
	left = 0
	right = 2 * k + 1
	min_so_far = n
	for x in range(1, 2 * k + 1):
		num_13 = 0
		num_13 += n // 2 - bisect_left(first, x)
		num_13 += n // 2 - bisect_left(second, x)
		coppie_2 = pre[min(x, k + 1) - 1]
		zero = somme[x]
		due = pre[max(0, x - k - 1)]
		mosse = num_13 + 2 * due + (coppie_2 - zero - due)
		min_so_far = min(min_so_far, mosse)
	print(min_so_far)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	p = []
	(i, j) = (0, n - 1)
	while i < j:
		p.append((min(a[i], a[j]), max(a[i], a[j])))
		i += 1
		j -= 1
	pref = [0] * (2 * k + 2)
	freq = [0] * (2 * k + 2)
	for pair in p:
		freq[pair[0] + pair[1]] += 1
		pref[pair[0] + 1] += 1
		pref[pair[1] + k + 1] -= 1
	for m in range(2, 2 * k + 2):
		pref[m] += pref[m - 1]
	smin = 10 ** 9
	for m in range(2, 2 * k + 1):
		one = pref[m] - freq[m]
		two = n // 2 - pref[m]
		smin = min(smin, one + two * 2)
	print(smin)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = []
	for i in range(n):
		for j in range(n - 2):
			if l[j] > l[j + 1]:
				(l[j], l[j + 2]) = (l[j + 2], l[j])
				(l[j], l[j + 1]) = (l[j + 1], l[j])
				s.append(j + 1)
				s.append(j + 1)
			elif l[j + 1] > l[j + 2]:
				(l[j], l[j + 1]) = (l[j + 1], l[j])
				(l[j], l[j + 2]) = (l[j + 2], l[j])
				s.append(j + 1)
	if l != sorted(l):
		print(-1)
	else:
		print(len(s))
		print(*s)


def make(vec, posi):
	(vec[posi + 1], vec[posi + 2]) = (vec[posi + 2], vec[posi + 1])
	(vec[posi], vec[posi + 1]) = (vec[posi + 1], vec[posi])
	return vec

def is_sorted(array):
	r = True
	for it in range(len(array) - 1):
		if array[it] > array[it + 1]:
			r = False
			break
	return r
for tc in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	res = []
	for i in range(n):
		res.append([ar[i], i])
	res = sorted(res)
	for i in range(n):
		ar[res[i][1]] = i
	cnt = 0
	for i in range(n):
		for j in range(i + 1, n):
			if ar[j] < ar[i]:
				cnt += 1
	if cnt & 1:
		for i in range(n - 1):
			if res[i][0] == res[i + 1][0]:
				(ar[res[i][1]], ar[res[i + 1][1]]) = (ar[res[i + 1][1]], ar[res[i][1]])
				break
	ans = []
	for i in range(n - 2):
		pos = ar.index(min(ar[i:n]))
		while pos > i + 1:
			ar = make(ar, pos - 2)
			ans.append(pos - 2)
			pos -= 2
		if pos != i:
			ar = make(ar, i)
			ar = make(ar, i)
			ans.append(i)
			ans.append(i)
			pos = i
	for i in range(3):
		if is_sorted(ar):
			break
		ar = make(ar, n - 3)
		ans.append(n - 3)
	if not is_sorted(ar):
		print(-1)
	else:
		ans = [ans[i] + 1 for i in range(len(ans))]
		print(len(ans))
		print(*ans)


from collections import defaultdict

def solve():
	[n, k] = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	assert len(a) == n and n % 2 == 0
	cnt = defaultdict(int)
	pref = [0] * (2 * k)
	for i in range(0, n // 2):
		x = a[i]
		y = a[n - i - 1]
		cnt[x + y] += 1
		lo = min(x, y) + 1
		hi = max(x, y) + k
		pref[hi - 1] += 1
		pref[lo - 2] -= 1
	for i in range(2 * k - 1 - 1, -1, -1):
		pref[i] += pref[i + 1]
	answer = float('inf')
	for x in range(2, 2 * k + 1):
		zeroes = cnt[x]
		ones = pref[x - 1] - cnt[x]
		twos = n // 2 - zeroes - ones
		answer = min(answer, 0 * zeroes + 1 * ones + 2 * twos)
	print(answer)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


def solve(a, k):
	half = len(a) // 2
	buckets = [0 for x in range(2 * (k + 2))]
	for i in range(half):
		min_value = min(a[i], a[~i])
		max_value = max(a[i], a[~i])
		buckets[1] += 2
		buckets[min_value + 1] -= 1
		buckets[min_value + max_value] -= 1
		buckets[min_value + max_value + 1] += 1
		buckets[max_value + k + 1] += 1
	curr = 0
	result = 99999999999999999999
	for i in buckets[1:]:
		curr += i
		result = min(result, curr)
	return result
for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	print(solve(a, k))


from itertools import accumulate
for t in range(int(input())):
	(n, k) = map(int, input().strip().split())
	arr = list(map(int, input().strip().split()))
	b = [0] * (2 * k + 2)
	c = [0] * (2 * k + 1)
	for i in range(n // 2):
		(x, y) = sorted([arr[i], arr[~i]])
		b[x + 1] += 1
		b[y + k + 1] -= 1
		c[x + y] += 1
	b = list(accumulate(b))
	d = [0] * (2 * k + 1)
	for i in range(2 * k + 1):
		d[i] = n - c[i] - b[i]
	d[0] = n
	d[1] = n
	print(min(d))


for _ in range(int(input())):
	(n, l, out) = (int(input()), list(map(lambda x: int(x) - 1, input().split())), [])
	ll = sorted([(l[i], i) for i in range(n)])
	swap = (-1, -1)
	newl = [0] * n
	for i in range(n - 1):
		if ll[i][0] == ll[i + 1][0]:
			swap = (ll[i][1], ll[i + 1][1])
	for i in range(n):
		newl[ll[i][1]] = i
	(l, swapN) = (newl, 0)
	(works, done) = (True, False)
	for i in range(n):
		for j in range(i + 1, n):
			if l[i] > l[j]:
				swapN += 1
	if swapN & 1:
		(l[swap[0]], l[swap[1]]) = (l[swap[1]], l[swap[0]])

	def shift(i):
		out.append(i + 1)
		(l[i], l[i + 1], l[i + 2]) = (l[i + 2], l[i], l[i + 1])
	while not done:
		for i in range(n):
			if l[i] != i:
				break
		else:
			done = True
		if done:
			break
		for find in range(i + 1, n):
			if l[find] == i:
				break
		while find - i >= 2:
			find -= 2
			shift(find)
		if find - i == 1:
			if find <= n - 2:
				shift(find - 1)
				shift(find - 1)
			else:
				works = False
				break
	if works:
		print(len(out))
		print(' '.join(map(str, out)))
	else:
		print(-1)


import sys
import bisect
from collections import Counter
input = lambda : sys.stdin.readline().strip()
t = int(input())

def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	pref = [0] * (2 * k + 2)
	cnt = [0] * (2 * k + 1)
	for i in range(n // 2):
		mi = min(a[i], a[n - 1 - i])
		ma = max(a[i], a[n - 1 - i])
		pref[mi + 1] += 1
		pref[ma + k + 1] -= 1
		cnt[a[i] + a[n - 1 - i]] += 1
	for i in range(2, 2 * k + 1):
		pref[i] += pref[i - 1]
	ans = n
	for i in range(2, 2 * k + 1):
		ans = min(ans, pref[i] - cnt[i] + (n // 2 - pref[i]) * 2)
	print(ans)
while t:
	t -= 1
	solve()


for _ in range(int(input())):
	(n, k) = [int(j) for j in input().split()]
	a = [int(x) for x in input().split()]
	lst = [n] + [0] * (k * 2)
	for i in range(n // 2):
		(x, y) = sorted((a[i], a[-(i + 1)]))
		lst[x] -= 1
		lst[x + y - 1] -= 1
		lst[x + y] += 1
		lst[k + y] += 1
	for i in range(2 * k):
		lst[i + 1] += lst[i]
	print(min(lst))


for j in range(int(input())):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	X = 10 ** 10
	B = []
	X0 = len(A)
	for i in range(len(A) // 2):
		B.append([min(A[i], A[-i - 1]) + 1, -1])
		B.append([k + max(A[i], A[-i - 1]) + 1, 1])
		B.append([A[i] + A[-i - 1], -1])
		B.append([A[i] + A[-i - 1] + 1, 1])
	B.sort(key=lambda n: n[0])
	for i in range(len(B)):
		if i > 0:
			if B[i][0] != B[i - 1][0]:
				if X0 < X:
					X = X0
		X0 += B[i][1]
	print(X)


t = int(input())
for a in range(t):
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	lookUp = dict()
	sumMinMax = []
	values = [0 for c in range(2 * k + 2)]
	for b in range(n // 2):
		pairSum = nums[b] + nums[n - b - 1]
		if pairSum in lookUp:
			lookUp[pairSum] += 1
		else:
			lookUp[pairSum] = 1
		sumMinMax.append([pairSum, 1 + min(nums[b], nums[n - b - 1]), k + max(nums[b], nums[n - b - 1])])
		values[1 + min(nums[b], nums[n - b - 1])] += 1
		values[k + max(nums[b], nums[n - b - 1]) + 1] -= 1
	sumPrevious = 0
	for c in range(len(values)):
		values[c] += sumPrevious
		sumPrevious = values[c]
	best = 0
	for key in lookUp:
		actual = lookUp[key] - (n // 2 - values[key])
		if actual > best:
			best = actual
	print(n // 2 - best)


import sys

def rotate(s, i, ans):
	(s[i], s[i + 1], s[i + 2]) = (s[i + 2], s[i], s[i + 1])
	ans.append(str(i + 1))
	return (s, ans)
t = int(input())
while t:
	ans = []
	n = int(input())
	s = list(map(int, sys.stdin.readline().split()))
	ss = s.copy()
	ss.sort()
	if len(s) == 3:
		t -= 1
		i = 0
		while True:
			if s == ss:
				print(len(ans))
				print(' '.join(ans))
				break
			(s, ans) = rotate(s, i, ans)
			if len(ans) == 3:
				print(-1)
				break
		continue
	j = 0
	c = 0
	l = len(ss)
	while j < l:
		k = ss[j]
		i = j + s[j:].index(k)
		while i - 2 >= j:
			i = i - 2
			(s, ans) = rotate(s, i, ans)
		if i != j:
			if j + 2 == l:
				if s[j] == s[j + 1]:
					break
				elif s[j - 1] == s[j + 1] and j != 0:
					ans.append(str(j))
					break
				elif len(ss) > len(set(ss)):
					for i in range(-2, -len(ss) - 1, -1):
						if s[i] == s[i + 1]:
							break
					if -i % 2 == 1:
						k = -3
						while k >= i:
							ans.append(str(l + k + 1))
							k -= 2
						ans.append(str(l + i + 1))
						k = 1
						while i + k < -2:
							ans.append(str(l + i + k + 1))
							ans.append(str(l + i + k + 1))
							k += 2
					else:
						k = -3
						while k >= i + 1:
							ans.append(str(l + k + 1))
							k -= 2
						ans.append(str(l + i + 1))
						k = 2
						while i + k < -2:
							ans.append(str(l + i + k + 1))
							ans.append(str(l + i + k + 1))
							k += 2
					break
				else:
					c = 1
					print(-1)
					break
			(s, ans) = rotate(s, j, ans)
			(s, ans) = rotate(s, j, ans)
			i -= 1
		j += 1
	if c == 0:
		print(len(ans))
		print(' '.join(ans))
	t -= 1


t = int(input())
while t > 0:
	t -= 1
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	cntx = [0] * (2 * k + 1)
	for i in range(int(n / 2)):
		cntx[a[i] + a[n - i - 1]] += 1
	rangex = [0] * (2 * k + 2)
	for i in range(int(n / 2)):
		rangex[min(a[i], a[n - i - 1]) + 1] += 1
		rangex[max(a[i], a[n - i - 1]) + k + 1] -= 1
	for i in range(1, len(rangex)):
		rangex[i] += rangex[i - 1]
	mini = 1000000
	for i in range(2, 2 * k + 1):
		curr = rangex[i] - cntx[i] + 2 * (int(n / 2) - rangex[i])
		if mini > curr:
			mini = curr
	print(mini)


from sys import stdin
input = stdin.readline
t = int(input())
for iwuehufiew in range(t):
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	odc = [[1 + min(l[i], l[n - 1 - i]), k + max(l[i], l[n - 1 - i])] for i in range(n // 2)]
	cyk = [0] * (2 * k + 2)
	for o in odc:
		cyk[o[0]] += 1
		cyk[o[1] + 1] -= 1
	cov = [0] * (2 * k + 2)
	cov[0] = cyk[0]
	for i in range(1, 2 * k + 2):
		cov[i] = cov[i - 1] + cyk[i]
	ilosc = [0] * (2 * k + 1)
	for i in range(n // 2):
		ilosc[l[i] + l[n - 1 - i]] += 1
	wyn = 759237598237985732489
	for i in range(2 * k + 1):
		a = cov[i] + (n // 2 - cov[i]) * 2 - ilosc[i]
		wyn = min(wyn, a)
	print(wyn)


import sys
input = sys.stdin.readline

def main():
	test = int(input())
	for _ in range(test):
		(n, k) = map(int, input().split())
		arr = [int(x) for x in input().split()]
		zeromove = [0 for i in range(2 * k + 2)]
		onemove = [0 for i in range(2 * k + 2)]
		for idx in range(0, n // 2):
			zeromove[arr[idx] + arr[n - idx - 1]] += 1
			left = min(arr[idx], arr[n - idx - 1]) + 1
			right = max(arr[idx], arr[n - idx - 1]) + k
			onemove[left] += 1
			onemove[right + 1] -= 1
		ans = n
		for pairsum in range(2, 2 * k + 1):
			onemove[pairsum] += onemove[pairsum - 1]
			zero = zeromove[pairsum]
			one = onemove[pairsum] - zero
			two = n // 2 - one - zero
			ans = min(ans, one + 2 * two)
			assert one >= 0
			assert two >= 0
		print(ans)
main()


def foo(n, data, k):
	farr = [0] * (2 * k + 1)
	sarr = [0] * (2 * k + 2)
	i = 0
	while i < n // 2:
		farr[data[i] + data[size - i - 1]] += 1
		i += 1
	i = 0
	while i < n // 2:
		sarr[min(data[i], data[size - i - 1]) + 1] += 1
		sarr[max(data[i], data[size - i - 1]) + k + 1] -= 1
		i += 1
	i = 1
	while i < 2 * k + 1:
		sarr[i] += sarr[i - 1]
		i += 1
	i = 0
	minimum = int(2 * 1000000.0)
	while i <= k * 2:
		minimum = min(minimum, sarr[i] - farr[i] + 2 * (n // 2 - sarr[i]))
		i += 1
	print(minimum)
test = int(input())
while test:
	(size, k) = [int(x) for x in input().split()]
	data = [int(i) for i in input().split()]
	foo(size, data, k)
	test -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	data = list(map(int, input().split()))
	in_map = {}
	out_map = {}
	temp_map = {}
	from_0 = set()
	for i in range(n // 2):
		min_value = min(data[i], data[n - i - 1])
		max_value = max(data[i], data[n - i - 1])
		lower_bound = min_value + 1
		higher_bound = max_value + k
		now_sum = min_value + max_value
		if lower_bound in in_map:
			in_map[lower_bound] += 1
		else:
			in_map[lower_bound] = 1
		if higher_bound in out_map:
			out_map[higher_bound] -= 1
		else:
			out_map[higher_bound] = -1
		if now_sum in temp_map:
			temp_map[now_sum] += 1
		else:
			temp_map[now_sum] = 1
		from_0.add(lower_bound)
		from_0.add(higher_bound)
		from_0.add(now_sum)
	sorted_set = sorted(from_0)
	my_sum = 0
	result = n
	for i in sorted_set:
		a = 0
		if i in in_map:
			a = in_map[i]
		my_sum += a
		t = 0
		if i in temp_map:
			t = temp_map[i]
		now_total = n - (my_sum + t)
		result = min(result, now_total)
		b = 0
		if i in out_map:
			b = out_map[i]
		my_sum += b
	print(result)


from sys import *
for t in range(int(stdin.readline())):
	n = int(stdin.readline())
	vec = [int(x) for x in stdin.readline().split()]
	ind = [x for x in range(n)]
	ans = []

	def shift(pos):
		ans.append(pos + 1)
		(vec[pos], vec[pos + 1], vec[pos + 2]) = (vec[pos + 2], vec[pos], vec[pos + 1])
	aux = vec.copy()
	aux.sort()
	for i in range(n):
		if vec[i] != aux[i]:
			j = 0
			for _ in range(i + 1, n):
				if vec[_] == aux[i]:
					j = _
					break
			while j - 2 >= i:
				j -= 2
				shift(j)
			if vec[i] == aux[i]:
				continue
			if i >= n - 2:
				break
			shift(i)
			shift(i)
	if vec[-1] < vec[-2] and vec[-1] == vec[-3]:
		shift(n - 3)
	if vec[-1] < vec[-2]:
		pos = 0
		for i in reversed(range(1, n - 2)):
			if vec[i] == vec[i - 1]:
				pos = i
				break
		if pos == 0:
			stdout.write(str(-1) + '\n')
			continue
		for i in reversed(range(pos - 1, n - 2)):
			shift(i)
	if vec[-1] < vec[-2]:
		stdout.write(str(-1) + '\n')
		continue
	stdout.write(str(len(ans)) + '\n')
	for i in ans:
		stdout.write(str(i) + ' ')
	stdout.write('\n')


import sys

def input():
	return sys.stdin.readline()
for _ in range(int(input().strip())):
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	common_values = [0 for _ in range(2 * k + 2)]
	for i in range(n // 2):
		(a, b) = (nums[i], nums[n - 1 - i])
		common_values[a + b - max(a, b) + 1] -= 1
		common_values[a + b] -= 1
		common_values[a + b + 1] += 1
		common_values[a + b - min(a, b) + k + 1] += 1
	common_values[1] = n
	minimum = n
	for i in range(2, 2 * k + 1):
		common_values[i] += common_values[i - 1]
		minimum = min(minimum, common_values[i])
	print(minimum)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	freq = [0 for i in range(2 * k + 5)]
	freq2 = [0 for i in range(2 * k + 5)]

	def check(ans1):
		ans = float('inf')
		best = 0
		for i in range(1, 2 * k + 5):
			tmp = 0
			for j in range(n // 2):
				if a[j] + a[n - j - 1] != i:
					if i - a[j] >= 1 and i - a[j] <= k:
						tmp += 1
					elif i - a[n - j - 1] >= 1 and i - a[n - j - 1] <= k:
						tmp += 1
					else:
						tmp += 2
			if tmp < ans:
				best = i
			ans = min(ans, tmp)
		return ans
	for i in range(n // 2):
		freq[min(a[n - 1 - i], a[i]) + 1] -= 1
		freq[0] += 1
		freq[max(a[n - 1 - i], a[i]) + k + 1] += 1
	for i in range(n // 2):
		freq2[a[i] + a[n - i - 1]] += 1
	ans = float('inf')
	for i in range(1, 2 * k + 1):
		freq[i] += freq[i - 1]
		ans = min(ans, freq[i] + n // 2 - freq2[i])
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	sum_costs = [n // 2] * (k * 2 + 1)
	lower_penalties = [0] * (k * 2 + 1)
	upper_penalties = [0] * (k * 2 + 1)
	for (ai, aj) in zip(a[:n // 2], reversed(a[n // 2:])):
		sum_costs[ai + aj] -= 1
		lower_penalties[min(ai, aj)] += 1
		if max(ai, aj) < k:
			upper_penalties[max(ai, aj) + k + 1] += 1
	for j in range(k * 2 - 1, -1, -1):
		lower_penalties[j] += lower_penalties[j + 1]
	for j in range(1, k * 2 + 1):
		upper_penalties[j] += upper_penalties[j - 1]
	for j in range(k * 2 + 1):
		sum_costs[j] += lower_penalties[j] + upper_penalties[j]
	print(min(sum_costs[2:]))


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from collections import deque
t = int(input())
for ii in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = [0] * (2 * k + 2)
	for i in range(n // 2):
		a = l[i]
		b = l[n - 1 - i]
		p = min(a, b)
		q = max(a, b)
		mi = p + 1
		ma = q + k
		d[0] += 2
		d[mi - 1] -= 2
		d[mi - 1] += 1
		d[p + q - 1] -= 1
		d[p + q] += 1
		d[ma] -= 1
		d[ma] += 2
		d[-1] -= 2
	for i in range(2 * k + 1):
		d[i + 1] += d[i]
	print(min(d[:-1]))
sys.exit()
N = 5
es = [[1, 2, 3], [0, 2], [0, 1], [0, 4], [3]]
colors = [0 for i in range(N)]

def dfs(v, color):
	print(v, color)
	colors[v] = color
	for to in es[v]:
		if colors[to] == color:
			return False
		if colors[to] == 0 and (not dfs(to, -color)):
			return False
	return True

def is_bipartite():
	return dfs(0, 1)
print(is_bipartite())


testCases = int(input())
while testCases > 0:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))[:n]
	(opened, closed, exist) = ({}, {}, {})
	for i in range(2 * k + 1):
		opened[i] = closed[i] = exist[i] = 0
	for i in range(int(n / 2)):
		(L, R) = (a[i], a[n - 1 - i])
		exist[L + R] += 1
		opened[1 + min(L, R)] += 1
		closed[k + max(L, R)] += 1
	(Answer, inside) = (10 ** 9, 0)
	for i in range(2 * k + 1):
		inside += opened[i]
		Answer = min(Answer, n - exist[i] - inside)
		inside -= closed[i]
	print(Answer)
	testCases -= 1


(res, a) = ([], [])

def rot(i: int) -> None:
	global res, a
	res.append(i + 1)
	(a[i], a[i + 1], a[i + 2]) = (a[i + 2], a[i], a[i + 1])

def solve():
	global res, a
	res.clear()
	input()
	a = [int(i) for i in input().split()]
	s = sorted(a)
	for i in range(len(a) - 2):
		if a[i] == s[i]:
			continue
		j = a.index(s[i], i, len(a))
		while j != i:
			if j - i >= 2:
				j -= 2
				rot(j)
			else:
				rot(i)
				j += 1
	if any((a[i] > a[i + 1] for i in range(len(a) - 1))):
		for i in range(len(a) - 3, -1, -1):
			while a[i + 2] < a[i] or a[i + 2] < a[i + 1]:
				rot(i)
		if all((a[i] != a[i + 1] for i in range(len(a) - 2))):
			print(-1)
			return
	print(len(res))
	print(' '.join((str(i) for i in res)))
t = int(input())
while t > 0:
	t -= 1
	solve()


from itertools import accumulate
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	cnt = [0] * (k * 2 + 1)
	l = list(map(int, input().split()))
	for (i, (a, b)) in enumerate(zip(l, l[:-1 - n // 2:-1]), 1):
		if a > b:
			(a, b) = (b, a)
		cnt[a] -= 1
		cnt[a + b - 1] -= 1
		cnt[a + b] += 1
		cnt[b + k] += 1
	print(n + min(accumulate(cnt)))


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def rotate(a, i):
	t = a[i + 2]
	a[i + 2] = a[i + 1]
	a[i + 1] = a[i]
	a[i] = t

def solve(n, a):
	sa = sorted(a)
	s = []
	rolled = False
	i = 0
	while i < n:
		for j in range(i, n):
			if a[j] == sa[i]:
				break
		while j - i >= 2:
			j -= 2
			rotate(a, j)
			s.append(j + 1)
		if i + 1 == j:
			if i + 2 < n:
				rotate(a, i)
				rotate(a, i)
				s.append(i + 1)
				s.append(i + 1)
			else:
				if rolled:
					wi(-1)
					return
				found = False
				for k in range(n - 2, 0, -1):
					if len(set(a[k - 1:k + 2])) == 2:
						found = True
						break
				if found:
					if a[k - 1] == a[k]:
						rotate(a, k - 1)
						rotate(a, k - 1)
						s.append(k)
						s.append(k)
					else:
						rotate(a, k - 1)
						s.append(k)
					rolled = True
					i = k - 2
				else:
					wi(-1)
					return
		i += 1
	if len(s) <= n * n:
		wi(len(s))
		wia(s)
	else:
		wi(-1)

def main():
	for _ in range(ri()):
		n = ri()
		a = ria()
		solve(n, a)
main()


def swap(i):
	tmp = a[i + 2]
	a[i + 2] = a[i + 1]
	a[i + 1] = a[i]
	a[i] = tmp
	ans.append(i + 1)
tt = int(input())
for loop in range(tt):
	n = int(input())
	a = list(map(int, input().split()))
	sa = 0.0001
	lis = [sa] * 501
	b1 = []
	b2 = []
	f2 = True
	for i in range(n):
		if lis[a[i]] != sa and f2:
			b1.append(a[i] + lis[a[i]])
			b2.append(a[i])
			f2 = False
		else:
			b1.append(a[i] + lis[a[i]])
			b2.append(a[i] + lis[a[i]])
		lis[a[i]] += sa
	ans = []
	a = b1
	for last in range(n - 3):
		mi = last
		for i in range(last, n):
			if a[i] < a[mi]:
				mi = i
		while mi != last:
			if mi - last >= 2:
				swap(mi - 2)
				mi -= 2
			else:
				swap(mi)
				mi += 1
	while not (a[-3] < a[-2] and a[-2] < a[-1]):
		swap(n - 3)
		if len(ans) > n ** 2:
			break
	if len(ans) <= n ** 2:
		print(len(ans))
		print(*ans)
		continue
	ans = []
	a = b2
	for last in range(n - 3):
		mi = last
		for i in range(last, n):
			if a[i] < a[mi]:
				mi = i
		while mi != last:
			if mi - last >= 2:
				swap(mi - 2)
				mi -= 2
			else:
				swap(mi)
				mi += 1
	while not (a[-3] < a[-2] and a[-2] < a[-1]):
		swap(n - 3)
		if len(ans) > n ** 2:
			break
	if len(ans) <= n ** 2:
		print(len(ans))
		print(*ans)
		continue
	print(-1)


from collections import defaultdict
import sys
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	m = []
	d = defaultdict(int)
	for i in range(n // 2):
		d[l[i] + l[n - i - 1]] += 1
	p = [0] * (2 * k + 2)
	for i in range(n // 2):
		p[min(l[i], l[n - i - 1]) + 1] += 1
		p[max(l[i], l[n - i - 1]) + k + 1] -= 1
	for i in range(1, 2 * k + 2):
		p[i] += p[i - 1]
	ans = sys.maxsize
	for i in range(2, 2 * k + 1):
		ans = min(ans, p[i] - d[i] + 2 * (n // 2 - p[i]))
	print(ans)


from bisect import bisect_left
from collections import Counter

def solve(n, k, a):
	s = [a[i] + a[n - i - 1] for i in range(n // 2)]
	amin = sorted([min(a[i], a[n - i - 1]) for i in range(n // 2)])
	amax = sorted([max(a[i], a[n - i - 1]) for i in range(n // 2)])
	ans = float('inf')
	counter = Counter(s)
	for v in range(2 * k + 1):
		count = n // 2 - bisect_left(amin, v)
		count1 = bisect_left(amax, v - k)
		count2 = n // 2 - count - count1
		count3 = counter[v]
		ans = min(ans, (count + count1) * 2 + count2 - count3)
	return ans

def main():
	tc = int(input())
	inp = lambda : [int(x) for x in input().split()]
	for _ in range(tc):
		(n, k) = inp()
		a = inp()
		print(solve(n, k, a))
main()


import collections
line = input()
t = int(line)
for _i in range(t):
	line = input()
	n = int(line)
	line = input()
	nums = [int(i) for i in line.split(' ')]
	res = collections.deque()
	for i in range(n - 2):
		for j in range(n - 3, i - 1, -1):
			if nums[j + 2] < nums[j + 1] and nums[j + 2] < nums[j]:
				(a, b, c) = (nums[j + 2], nums[j + 1], nums[j])
				(nums[j], nums[j + 1], nums[j + 2]) = (a, c, b)
				res.append(j + 1)
		if nums[i] > nums[i + 1]:
			(a, b, c) = (nums[i], nums[i + 1], nums[i + 2])
			(nums[i], nums[i + 1], nums[i + 2]) = (b, c, a)
			res.append(i + 1)
			res.append(i + 1)
	if nums[n - 3] == nums[n - 1] and nums[n - 2] > nums[n - 1]:
		res.append(n - 2)
		(nums[n - 1], nums[n - 2]) = (nums[n - 2], nums[n - 1])
	if nums[-1] < nums[-2]:
		i = n - 2
		while i >= 0 and nums[i] != nums[i + 1]:
			i -= 1
		if i < 0:
			print(-1)
		else:
			while i < n - 2:
				res.append(i + 1)
				res.append(i + 1)
				i += 1
			print(len(res))
			for i in res:
				print(i, end=' ')
			print()
	else:
		print(len(res))
		for i in res:
			print(i, end=' ')
		print()


A = [0 for x in range(400005)]
t = int(input())

def mymin(a, b):
	if a < b:
		return a
	else:
		return b

def mymax(a, b):
	if a > b:
		return a
	else:
		return b
for tests in range(t):
	[n, k] = input().split()
	n = int(n)
	k = int(k)
	B = input().split()
	for i in range(2, 2 * k + 1):
		A[i] = 0
	n2 = int(n / 2)
	for i in range(n2):
		B[i] = int(B[i])
		B[n - 1 - i] = int(B[n - 1 - i])
		mi = mymin(B[i], B[n - 1 - i])
		ma = mymax(B[i], B[n - 1 - i])
		A[2] += 2
		A[mi + 1] -= 1
		A[mi + ma] -= 1
		if mi + ma + 1 <= 2 * k:
			A[mi + ma + 1] += 1
		if ma + k + 1 <= 2 * k:
			A[ma + k + 1] += 1
	ans = n
	for i in range(2, 2 * k + 1):
		A[i] += A[i - 1]
		if A[i] < ans:
			ans = A[i]
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	(a_d, b_d, ab_d) = ([0] * (2 * k + 3), [0] * (2 * k + 3), [0] * (2 * k + 3))
	for i in range(int(n / 2)):
		(a, b) = (l[i], l[n - i - 1])
		(a, b) = (min(a, b), max(a, b))
		a_d[a + 1] += 1
		b_d[k + b + 1] += 1
		ab_d[a + b] += 1
	val = n
	sol = n
	for i in range(len(ab_d)):
		val = val - a_d[i] + b_d[i]
		sol = min(val - ab_d[i], sol)
	print(sol)


import itertools
numcases = int(input())

def minmoves(asum, a, k):
	count = {x: 0 for x in range(2 * k + 1)}
	ans = 1000000
	moves = 0
	for sum in asum:
		count[sum] = count[sum] + 1
	rangex = [0 for i in range(2 * k + 2)]
	(lower, upper) = (0, 0)
	for i in range(int(n / 2)):
		lower = min(a[i], a[n - 1 - i]) + 1
		upper = max(a[i], a[n - 1 - i]) + k
		rangex[lower] += 1
		rangex[upper + 1] -= 1
	prefix = list(itertools.accumulate(rangex))
	for i in range(2, 2 * k + 1):
		moves = prefix[i] - count[i] + 2 * (n / 2 - prefix[i])
		if moves < ans:
			ans = moves
	return ans
for z in range(numcases):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	asum = []
	sols = []
	for i in range(int(n / 2)):
		asum.append(a[i] + a[n - 1 - i])
	ans = minmoves(asum, a, k)
	print(int(ans))


import io
import os
from collections import Counter, deque
DEBUG = False

def solve(N, A):
	original = list(A)
	sortedA = sorted(A)
	if N <= 5:

		def doMove(A, i):
			assert i + 2 < N
			A = list(A)
			return tuple(A[:i] + [A[i + 2], A[i], A[i + 1]] + A[i + 3:])
		moves = None
		source = tuple(A)
		dest = tuple(sortedA)
		q = deque([source])
		moveFromParent = {source: None}
		while q:
			node = q.popleft()
			if node == dest:
				moves = []
				while moveFromParent[node] is not None:
					i = moveFromParent[node]
					moves.append(i)
					node = doMove(node, i)
					node = doMove(node, i)
				moves = moves[::-1]
				break
			for i in range(N - 2):
				nbr = doMove(node, i)
				if nbr not in moveFromParent:
					q.append(nbr)
					moveFromParent[nbr] = i
		if moves is None:
			return -1
	else:
		moves = []
		for (i, target) in enumerate(sortedA):
			index = A.index(target)
			del A[index]
			j = i + index
			while j >= i + 2:
				j -= 2
				moves.append(j)
			assert i <= j <= i + 1
			if j == i + 1:
				assert len(A) > 0
				if len(A) >= 2:
					moves.append(i)
					moves.append(i)
					(A[0], A[1]) = (A[1], A[0])
				else:
					assert len(A) == 1
					if A[0] == target:
						break
					if sortedA[i - 1] == target:
						moves.append(i - 1)
						break
					assert sortedA[i - 1] < target < A[0]
					dupes = set((k for (k, v) in Counter(sortedA).items() if v > 1))
					if not dupes:
						return -1
					assert j == N - 1
					while sortedA[j - 1] not in dupes:
						moves.append(j - 2)
						j -= 2
					assert sortedA[j - 1] in dupes
					if sortedA[j] in dupes:
						moves.append(j - 1)
						j += 1
					else:
						assert sortedA[j - 2] in dupes
						moves.append(j - 2)
						moves.append(j - 2)
						j -= 1
					while j != N - 2:
						moves.append(j)
						moves.append(j)
						j += 2
					break
	if DEBUG:
		A = original
		for i in moves:
			assert i + 3 <= N
			A[i:i + 3] = (A[i + 2], A[i], A[i + 1])
		assert A == sortedA
	if len(moves) <= N * N:
		return str(len(moves)) + '\n' + ' '.join((str(x + 1) for x in moves))
	return -1
if DEBUG:
	import random
	random.seed(0)
	for t in range(1000):
		A = [random.randint(0, 10) for i in range(100)]
		solve(len(A), A)
	A = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 11]
	print(solve(len(A), A))
	A = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 11]
	print(solve(len(A), A))
	exit()
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


from collections import defaultdict
from itertools import accumulate

def solve(a, n, k):
	pairs = [(min(x, y), max(x, y)) for (x, y) in zip(a[:n], a[::-1][:n])]
	one_change = [(x + 1, y + k) for (x, y) in pairs]
	changes = [0] * (2 * k + 2)
	for (a, b) in one_change:
		changes[a] += 1
		changes[b + 1] -= 1
	changes = list(accumulate(changes))
	for (x, y) in pairs:
		changes[x + y] += 1
	print(2 * n - max(changes[2:2 * k + 1]))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	solve(a, n // 2, k)


from collections import deque
from collections import OrderedDict
import math
maxValue = 2 * 100000 + 2
for t in range(int(input())):
	(n, k) = map(int, input().split())
	arrIn = input().split()
	dp = [0] * (2 * max(k + 1, n + 1))
	dp1 = [0] * (2 * max(k + 1, n + 1))
	for i in range(len(arrIn)):
		arrIn[i] = int(arrIn[i])
	for i in range(len(arrIn) // 2):
		x = arrIn[i]
		y = arrIn[len(arrIn) - i - 1]
		dp[2] += 2
		dp[min(x, y) + 1] -= 2
		dp[min(x, y) + 1] += 1
		dp[x + y] -= 1
		dp[x + y + 1] += 1
		dp[max(x, y) + k + 1] -= 1
		dp[max(x, y) + k + 1] += 2
	for i in range(1, k * 2 + 1):
		dp1[i] = dp1[i - 1] + dp[i]
	answer = maxValue
	for i in range(2, k * 2 + 1):
		answer = min(answer, dp1[i])
	print(answer)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cntx = [0] * (2 * k + 1)
	prefx = [0] * (2 * k + 2)
	for i in range(n // 2):
		cntx[a[i] + a[n - i - 1]] += 1
		prefx[min(a[i], a[n - i - 1]) + 1] += 1
		prefx[max(a[i], a[n - i - 1]) + k + 1] += -1
	ans = n
	p = 0
	for i in range(2, 2 * k + 1):
		p += prefx[i]
		ans = min(ans, p - cntx[i] + (n // 2 - p) * 2)
	print(ans)


q = int(input())
for _ in range(q):
	(n, k) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	ans = [0 for i in range(2 * k + 1)]
	if n == 2:
		print(0)
		continue
	for j in range(n // 2):
		(x, y) = (arr[j], arr[n - 1 - j])
		mid = x + y
		endr = max(x, y) + k
		endl = min(x, y) + 1
		if mid < endr:
			ans[mid + 1] += 1
			if endr < 2 * k:
				ans[endr + 1] += 1
		if endl < mid:
			ans[endl] += 1
			ans[mid] -= 1
			if 2 < endl:
				ans[2] += 2
				ans[endl] -= 2
	for i in range(1, 2 * k + 1):
		ans[i] += ans[i - 1]
	(ans[0], ans[1]) = (float('inf'), float('inf'))
	print(min(ans))


def max_overlap(start, end):
	n = len(start)
	start.sort()
	end.sort()
	inter = 1
	max_inter = 1
	i = 1
	j = 0
	while i < n and j < n:
		if start[i] <= end[j]:
			inter += 1
			if inter > max_inter:
				max_inter = inter
			i += 1
		else:
			inter -= 1
			j += 1
	return max_inter
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	total = 0
	start = []
	end = []
	for i in range(n // 2):
		(small, big) = (a[i], a[n - i - 1])
		if small > big:
			(small, big) = (big, small)
		mini = small + 1
		maxi = big + k
		start.append(mini)
		end.append(maxi + 0.1)
		start.append(big + small)
		end.append(big + small + 0.1)
	overlap = max_overlap(start, end)
	print(n - overlap)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	lst = [0] * (2 * k + 2)
	interval = []
	for i in range(n // 2):
		st = min(a[i], a[n - 1 - i])
		s = a[i] + a[n - 1 - i]
		end = s - st + k
		lst[st + 1] += 1
		lst[end + 1] -= 1
		lst[s] += 1
		lst[s + 1] -= 1
	cur = 0
	idx = 0
	interval = [0, 0]
	maxy = -1
	for i in range(2 * k + 1):
		cur += lst[i]
		if maxy < cur:
			maxy = cur
			idx = i
			interval[0] = i
		if lst[i] < 0:
			interval[1] = i - 1
	res = idx
	ans = 0
	for i in range(n // 2):
		st = min(a[i], a[n - 1 - i])
		s = a[i] + a[n - 1 - i]
		end = s - st + k
		if res == s:
			continue
		elif st + 1 <= res <= end:
			ans += 1
		else:
			ans += 2
	print(ans)


def solve():
	(n, k) = [int(i) for i in input().split()]
	v = [int(i) for i in input().split()]
	sum = [0] * (2 * k + 2)
	for i in range(n // 2):
		x = v[i]
		y = v[n - i - 1]
		if y > x:
			(x, y) = (y, x)
		sum[x + y] += 1
		sum[x + k + 1] -= 1
		sum[y + 1] += 1
		sum[x + y + 1] -= 1
	pos = -1
	mx = -9999999
	for i in range(len(sum)):
		sum[i] += sum[i - 1]
		if sum[i] > mx:
			mx = sum[i]
			pos = i
	elem = pos
	c = 0
	for i in range(n // 2):
		x = v[i]
		y = v[n - i - 1]
		if y > x:
			(x, y) = (y, x)
		if elem >= y + 1 and elem <= x + k:
			if x + y != elem:
				c += 1
		else:
			c += 2
	print(c)
t = int(input())
while t:
	t -= 1
	solve()


import collections
import operator
n = int(input())
for i in range(n):
	mk = [int(i) for i in input().split(' ')]
	m = mk[0]
	k = mk[1]
	ll = [int(i) for i in input().split(' ')]
	rr = [0] * (2 * k + 2)
	pref = [0] * (2 * k + 2)
	lt = [0] * (2 * k + 2)
	for i in range(m // 2):
		rr[ll[i] + ll[m - 1 - i]] += 1
	for i in range(m // 2):
		a = min(ll[i] + 1, ll[m - 1 - i] + 1)
		b = max(ll[i] + k, ll[m - i - 1] + k) + 1
		pref[a] += 1
		pref[b] -= 1
	for i in range(1, 2 * k + 1):
		pref[i] += pref[i - 1]
	ans = m
	for i in range(2, 2 * k + 1):
		ans = min(ans, pref[i] - rr[i] + (m // 2 - pref[i]) * 2)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cnt_zero = [0] * (2 * k + 5)
	cnt_zero_or_one = [0] * (2 * k + 5)
	(i, j) = (0, n - 1)
	while i < j:
		actual_sum = a[i] + a[j]
		cnt_zero[actual_sum] += 1
		min_sum = min(a[i], a[j]) + 1
		max_sum = max(a[i], a[j]) + k
		cnt_zero_or_one[min_sum] += 1
		cnt_zero_or_one[max_sum + 1] -= 1
		i += 1
		j -= 1
	for i in range(1, len(cnt_zero_or_one)):
		cnt_zero_or_one[i] += cnt_zero_or_one[i - 1]
	ans = 2 ** 31
	for x in range(2, len(cnt_zero_or_one)):
		cnt_one_only = cnt_zero_or_one[x] - cnt_zero[x]
		cnt_two = n / 2 - cnt_zero_or_one[x]
		ans = min(ans, cnt_one_only + cnt_two * 2)
	print(int(ans))


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	if n == 2:
		print(0)
	else:
		count = [0] * (2 * k)
		for j in range(n // 2):
			count[arr[j] + arr[-j - 1] - 1] += 1
		pref = [0] * (2 * k)
		for j in range(n // 2):
			x1 = arr[j] + 1
			x2 = arr[-j - 1] + 1
			y1 = arr[j] + k
			y2 = arr[-j - 1] + k
			pref[min(x1, x2) - 1] += 1
			if max(y1, y2) < 2 * k:
				pref[max(y1, y2)] -= 1
		for j in range(1, 2 * k):
			pref[j] += pref[j - 1]
		ans = n // 2
		for j in range(1, 2 * k):
			temp = pref[j] - count[j] + 2 * (n // 2 - pref[j])
			ans = min(ans, temp)
		print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	data = list(map(int, input().split()))
	in_map = {}
	out_map = {}
	sum_map = {}
	points = set()
	for i in range(n // 2):
		min_value = min(data[i], data[n - i - 1])
		max_value = max(data[i], data[n - i - 1])
		lower_bound = min_value + 1
		upper_bound = max_value + k
		sum_value = min_value + max_value
		if lower_bound in in_map:
			in_map[lower_bound] += 1
		else:
			in_map[lower_bound] = 1
		if upper_bound in out_map:
			out_map[upper_bound] += 1
		else:
			out_map[upper_bound] = 1
		if sum_value in sum_map:
			sum_map[sum_value] += 1
		else:
			sum_map[sum_value] = 1
		points.add(lower_bound)
		points.add(upper_bound)
		points.add(sum_value)
	points = sorted(points)
	now_sum = 0
	result = n
	for i in points:
		in_count = 0
		if i in in_map:
			in_count = in_map[i]
		now_sum += in_count
		sum_count = 0
		if i in sum_map:
			sum_count = sum_map[i]
		now_total = n - (now_sum + sum_count)
		result = min(result, now_total)
		out_count = 0
		if i in out_map:
			out_count = out_map[i]
		now_sum -= out_count
	print(result)


import sys

def input():
	return sys.stdin.readline()[:-1]
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cum = [0 for _ in range(2 * k + 2)]
	for i in range(n // 2):
		(x, y) = (a[i], a[n - i - 1])
		cum[2] += 2
		cum[min(x, y) + 1] -= 1
		cum[x + y] -= 1
		cum[x + y + 1] += 1
		cum[max(x, y) + k + 1] += 1
		cum[2 * k + 1] -= 2
	ans = n
	for i in range(2, 2 * k + 1):
		cum[i] += cum[i - 1]
		ans = min(ans, cum[i])
	print(ans)


from sys import stdin, stdout
for case in range(int(stdin.readline())):
	(n, k) = [int(x) for x in stdin.readline().split()]
	a = [int(x) for x in stdin.readline().split()]
	a1 = a[:n // 2]
	a2 = a[n // 2:][::-1]
	for x in range(n // 2):
		if a1[x] > a2[x]:
			(a1[x], a2[x]) = (a2[x], a1[x])
	lows = {}
	lowCount = [0 for x in range(max(a1) + 1)]
	highCount = [0 for x in range(max(a2) + 1)]
	for x in a1:
		lowCount[x] += 1
	for x in a2:
		highCount[x] += 1
	lowSums = [highCount[0]]
	highSums = [lowCount[-1]]
	for x in highCount[1:]:
		lowSums.append(lowSums[-1] + x)
	for x in lowCount[:-1][::-1]:
		highSums.append(highSums[-1] + x)
	highSums = highSums[::-1]
	sums = {}
	for x in range(n // 2):
		if a1[x] + a2[x] in sums:
			sums[a1[x] + a2[x]] += 1
		else:
			sums[a1[x] + a2[x]] = 1
	best = n // 2
	for x in sums:
		total = n // 2 - sums[x]
		if x > k:
			total += lowSums[x - k - 1]
		if x < len(highSums):
			total += highSums[x]
		best = min(best, total)
	print(best)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0] * (2 * k + 2)
	for i in range(n // 2):
		x = a[i] + a[n - i - 1]
		(p, q) = (min(a[i], a[n - i - 1]), max(a[i], a[n - i - 1]))
		b[p + 1] -= 1
		b[q + k + 1] += 1
	for i in range(2, 2 * k + 1):
		b[i] += b[i - 1]
	for i in range(n // 2):
		x = a[i] + a[n - i - 1]
		b[x] -= 1
	ans = min(b)
	print(ans + n)


from collections import Counter, defaultdict

def get_by(x):
	c = 0
	for i in range(n // 2):
		if x == a[i] + a[n - 1 - i]:
			continue
		if k + a[n - 1 - i] < x:
			c += 2
		else:
			c += 1
	return c
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = defaultdict(int)
	original_counter = Counter()
	one_diff_counter = Counter()
	for i in range(n // 2):
		(x, y) = (a[i], a[n - i - 1])
		original_counter[x + y] += 1
		one_diff_counter[min(x, y) + 1] += 1
		one_diff_counter[max(x, y) + k + 1] -= 1
	one_diff = 0
	minimum_change = float('inf')
	for i in range(2, 2 * k + 1):
		zero_diff = original_counter[i]
		one_diff += one_diff_counter[i]
		two_diff = n - zero_diff - one_diff * 2
		change = one_diff + two_diff
		minimum_change = min(minimum_change, change)
	print(minimum_change)


def solve():
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	cnt = [0] * (2 * k + 2)
	for i in range(n // 2):
		sum = a[i] + a[n - i - 1]
		cnt[2] += 2
		cnt[sum - max(a[i], a[n - i - 1]) + 1] -= 1
		cnt[sum] -= 1
		cnt[sum + 1] += 1
		cnt[sum + k - min(a[i], a[n - i - 1]) + 1] += 1
	ans = n
	for i in range(2, 2 * k + 1):
		cnt[i] += cnt[i - 1]
		ans = min(ans, cnt[i])
	print(ans)
t = int(input())
while t > 0:
	t -= 1
	solve()


from sys import stdin, stdout
from math import *
for __ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = list(map(int, input().split()))
	r1 = {}
	r2 = {}
	h = [0] * (m + m + 1)
	for i in range(n // 2):
		x = ar[i]
		y = ar[-(i + 1)]
		h[x + y] -= 1
		a = 1 + min(x, y)
		b = m + max(x, y)
		if r1.get(a) == None:
			r1[a] = 1
		else:
			r1[a] += 1
		if r2.get(b) == None:
			r2[b] = 1
		else:
			r2[b] += 1
	ans = n
	rslt = n
	for i in range(2, m + m + 1):
		if r1.get(i) != None:
			ans -= r1[i]
		rslt = min(ans + h[i], rslt)
		if r2.get(i) != None:
			ans += r2[i]
	print(rslt)


import sys

def main():
	T = int(input())
	for _ in range(T):
		(n, k) = map(int, input().split())
		nums = list(map(int, input().split()))
		dp = [0] * (2 * k + 2)
		for i in range(n // 2):
			(a, b) = (nums[i], nums[n - 1 - i])
			if a > b:
				(a, b) = (b, a)
			s = a + b
			lo = s - (b - 1)
			hi = s + (k - a)
			dp[lo] -= 1
			dp[s] -= 1
			dp[s + 1] += 1
			dp[hi + 1] += 1
		mn = n
		cur = n
		for i in range(2, 2 * k + 1):
			cur += dp[i]
			mn = min(cur, mn)
		print(mn)
main()


from bisect import bisect, bisect_left, bisect_right

def solve():
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	ocr = {}
	mpv = [None] * (n // 2)
	spv = [None] * (n // 2)
	for i in range(n // 2):
		x = ar[i] + ar[n - i - 1]
		mpx = max(ar[i], ar[n - i - 1]) + k
		spx = min(ar[i], ar[n - i - 1]) + 1
		spv[i] = spx
		mpv[i] = mpx
		if x in ocr:
			ocr[x] += 1
		else:
			ocr[x] = 1
	mpv.sort()
	spv.sort()
	best = n // 2
	for (x, oc) in ocr.items():
		over = bisect_left(mpv, x, 0, len(mpv))
		under = n // 2 - bisect_right(spv, x, 0, len(spv))
		cur = n // 2 - oc + over + under
		if cur < best:
			best = cur
	print(best)
t = int(input())
for _ in range(t):
	solve()


def cnt_inv(a):
	ans = 0
	for i in range(len(a)):
		for f in range(i + 1, len(a)):
			if a[f] < a[i]:
				ans += 1
	return ans
for testcase in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	inv = cnt_inv(a)
	sorted_a = list(sorted(a))
	last_eq = -1
	for i in range(n - 1):
		if sorted_a[i] == sorted_a[i + 1]:
			last_eq = i + 1
	ans = []

	def shift(pos):
		global inv
		inv -= int(a[pos] > a[pos + 1]) + int(a[pos] > a[pos + 2]) + int(a[pos + 1] > a[pos + 2])
		(a[pos], a[pos + 1], a[pos + 2]) = (a[pos + 2], a[pos], a[pos + 1])
		inv += int(a[pos] > a[pos + 1]) + int(a[pos] > a[pos + 2]) + int(a[pos + 1] > a[pos + 2])
		ans.append(pos + 1)
	for i in range(n - 3):
		pos = min(range(i, n), key=lambda x: a[x])
		while pos > i + 1:
			shift(pos - 2)
			pos -= 2
		if pos == i + 1:
			shift(i)
			shift(i)
		if i == last_eq and inv % 2 == 1:
			shift(i)
			shift(i - 1)
	last_min = min(*a[-3:])
	while a[-3] != last_min:
		shift(n - 3)
	if n - 3 == last_eq and inv % 2 == 1:
		shift(n - 3)
		shift(n - 4)
	cnt = 0
	while not a[-3] <= a[-2] <= a[-1]:
		shift(n - 3)
		cnt += 1
		if cnt > 5:
			break
	if cnt > 5:
		print(-1)
	else:
		print(len(ans))
		print(' '.join(map(str, ans)))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
import traceback
for T in range(int(input())):
	n = int(input())
	d = {}
	prev = {}
	li = [int(i) * 501 for i in input().split(' ')]
	sol = False
	invs = 0
	for (p, i) in enumerate(li):
		if i in d:
			li[p] += d[i]
			if not sol:
				sol = True
				tar1 = prev[i]
				tar2 = p
		d[i] = 1 + d.get(i, 0)
		prev[i] = p
		for (k, v) in d.items():
			if k > i:
				invs += v
	if invs & 1 and sol == False:
		print(-1)
		continue
	if invs == 0:
		print(0)
		print()
		continue
	ansQ = []
	ans = 0
	c = False
	if sol and invs & 1:
		(li[tar1], li[tar2]) = (li[tar2], li[tar1])
	il = sorted(li)
	try:
		for (p, i) in enumerate(il):
			if il[p] != li[p]:
				pos = li.index(i, p)
				try:
					while pos != p:
						if pos - p > 1:
							(li[pos], li[pos - 1], li[pos - 2]) = (li[pos - 1], li[pos - 2], li[pos])
							ansQ.append(pos - 2 + 1)
							ans += 1
							pos -= 2
						else:
							(li[pos - 1], li[pos], li[pos + 1]) = (li[pos], li[pos + 1], li[pos - 1])
							ans += 2
							ansQ.append(pos - 1 + 1)
							ansQ.append(pos - 1 + 1)
							pos -= 1
				except:
					print(*li[-20:])
					print(*il[-20:])
					print(sol)
	except:
		print(traceback.format_exc())
	if ans <= n ** 2:
		print(ans)
		print(*ansQ)
	else:
		print(-1)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(var):
	sys.stdout.write(str(var))

def outln(var):
	sys.stdout.write(str(var) + '\n')

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(n, k) = sp()
	arr = l()
	diff = dd(int)
	temp = dd(int)
	for i in range(n // 2):
		diff[arr[i] + arr[n - i - 1]] += 1
		low = 1 + min(arr[i], arr[n - i - 1])
		high = k + max(arr[i], arr[n - i - 1])
		temp[low] += 1
		temp[high + 1] -= 1
	for i in range(1, 2 * k + 2):
		temp[i] += temp[i - 1]
	answer = n // 2
	for i in range(2, 2 * k + 1):
		answer = min(answer, temp[i] + 2 * (n // 2 - temp[i]) - diff[i])
	outln(answer)


def solve(n, k, arr):
	temp = [0 for i in range(0, 2 * k + 10)]
	for i in range(0, n // 2):
		v1 = arr[i]
		v2 = arr[n - 1 - i]
		p1 = min(v1, v2) + 1
		p2 = v1 + v2
		p3 = max(v1, v2) + k
		temp[2] += 2
		temp[p1] -= 1
		temp[p2] -= 1
		temp[p2 + 1] += 1
		temp[p3 + 1] += 1
	res = n
	cur = 0
	for i in range(2, 2 * k + 1):
		cur += temp[i]
		res = min(cur, res)
	return res
t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	res = solve(n, k, arr)
	print(res)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	(start, end) = (2, 2 * k)
	ans = float('inf')
	pairs = n // 2
	temp = [0] * (2 * k + 1)
	d = {}
	for i in range(n // 2):
		val = arr[i] + arr[n - i - 1]
		if val not in d:
			d[val] = 1
		else:
			d[val] += 1
	for i in range(n // 2):
		mm = min(arr[i], arr[n - i - 1]) + 1
		maxx = max(min(arr[i] + k, 2 * k), min(arr[n - i - 1] + k, 2 * k))
		temp[mm] += 1
		if maxx + 1 <= 2 * k:
			temp[maxx + 1] -= 1
	for i in range(1, 2 * k + 1):
		temp[i] += temp[i - 1]
	for num in range(start, end + 1):
		zeros = ones = twos = 0
		if num in d:
			zeros = d[num]
		ones = temp[num] - zeros
		twos = pairs - ones - zeros
		val = ones + twos * 2
		ans = min(ans, val)
	print(ans)


import sys
input = sys.stdin.buffer.readline
from itertools import accumulate
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	B = [0] * (2 * k + 2)
	for i in range(n // 2):
		m = min(A[i], A[n - 1 - i])
		M = max(A[i], A[n - 1 - i])
		s = A[i] + A[n - 1 - i]
		l = m + 1
		r = M + k
		B[0] += 2
		B[l] -= 2
		B[r + 1] += 2
		B[-1] -= 2
		B[l] += 1
		B[s] -= 1
		B[s + 1] += 1
		B[r + 1] -= 1
	C = list(accumulate(B))
	ans = 10 ** 18
	for i in range(2, 2 * k + 1):
		ans = min(ans, C[i])
	print(ans)


inp = input
li = list
iinp = lambda : int(inp())
ent = lambda : map(int, inp().split())
lient = lambda : [int(i) for i in inp().split()]
li0 = lambda x: [0 for i in range(x)]
stent = lambda : [i for i in inp()]
mi = min
ma = max
l = len
t = iinp()
for _ in range(t):
	(lon, valormax) = ent()
	numeros = lient()
	s = [0] * (2 * valormax + 2)
	for i in range(lon // 2):
		puntero1 = numeros[i]
		puntero2 = numeros[lon - i - 1]
		s[2] += 2
		s[mi(puntero1, puntero2) + 1] -= 1
		s[ma(puntero1, puntero2) + valormax + 1] += 1
		s[puntero1 + puntero2] -= 1
		s[puntero1 + puntero2 + 1] += 1
	for i in range(2, 2 * valormax + 2):
		s[i] += s[i - 1]
	print(mi(s[2:]))


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dic = {i: 0 for i in range(2, 2 * k + 5)}
	pref = [0] * (2 * k + 5)
	for i in range(n // 2):
		(l, r) = (min(a[i], a[n - i - 1]), max(a[i], a[n - i - 1]))
		dic[l + r] += 1
		pref[l + 1] += 1
		pref[r + k + 1] -= 1
	for i in range(2, 2 * k + 1):
		pref[i] += pref[i - 1]
	ans = n
	for i in range(2, 2 * k + 1):
		chng0 = dic[i]
		chng1 = pref[i] - chng0
		chng2 = n // 2 - chng0 - chng1
		ans = min(ans, chng1 + chng2 * 2)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	up = 2 * k + 2
	count = [0] * up
	bounds = [0] * up
	for i in range(n // 2):
		(minm, maxm) = (min(a[i] + 1, a[n - i - 1] + 1), max(a[i] + k, a[n - i - 1] + k))
		count[minm + maxm - 1 - k] += 1
		bounds[maxm + 1] -= 1
		bounds[minm] += 1
	for i in range(1, up - 1):
		bounds[i] += bounds[i - 1]
	ans = 10 ** 7
	for i in range(2, up):
		ans = min(ans, bounds[i] - count[i] + 2 * (n // 2 - bounds[i]))
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	c = []
	for i in range(n - 2):
		ind = a[i:].index(b[i]) + i
		if a[i] == b[i]:
			continue
		while ind != i:
			if ind - i >= 2:
				c.append(ind - 1)
				temp1 = a[ind - 2]
				temp2 = a[ind - 1]
				a[ind - 2] = a[ind]
				a[ind - 1] = temp1
				a[ind] = temp2
				ind -= 2
			elif ind - i == 1:
				c.append(i + 1)
				c.append(i + 1)
				temp1 = a[i]
				temp2 = a[ind + 1]
				a[i] = a[ind]
				a[i + 1] = temp2
				a[i + 2] = temp1
				ind -= 1
	if a[-2] <= a[-1]:
		print(len(c))
		for i in c:
			print(i, end=' ')
		print()
	else:
		check = False
		if n > 3:
			for i in range(n - 3, 0, -1):
				if a[i] == a[i - 1]:
					check = True
					ind = i - 1
		if not check:
			if n >= 3 and a[-3] == a[-1]:
				c.append(n - 2)
				print(len(c))
				for i in c:
					print(i, end=' ')
				print()
			else:
				print('-1')
		else:
			for i in range(ind + 1, n - 1):
				c.append(i)
				c.append(i)
			print(len(c))
			for i in c:
				print(i, end=' ')
			print()


t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = [0] * (2 * k + 2)
	d = {}
	for y in range(0, n // 2):
		l = min(l1[y], l1[n - y - 1]) + 1
		r = max(l1[y], l1[n - y - 1]) + k
		l2[l] += 1
		l2[r + 1] -= 1
		sum = l1[y] + l1[n - y - 1]
		if sum in d.keys():
			d[sum] += 1
		else:
			d[sum] = 1
	l1 = [l2[0]]
	for y in range(1, len(l2)):
		l1.append(l1[-1] + l2[y])
	m = 10000000
	for j in range(2, 2 * k + 1):
		a = 0
		c = 0
		if j in d.keys():
			a = d[j]
		b = l1[j] - a
		c = n // 2 - b - a
		if b + 2 * c < m:
			m = b + 2 * c
	print(m)


for _ in range(int(input())):
	(n, k) = [int(s) for s in input().split()]
	arr = [int(s) for s in input().split()]
	f1 = [0] * (2 * k + 1)
	f2 = [0] * (2 * k + 1)
	f3 = [0] * (2 * k + 1)
	for i in range(n // 2):
		a = arr[i]
		b = arr[n - i - 1]
		f1[a + b] += 1
		f2[max(a, b) + k] += 1
		f3[1 + min(a, b)] += 1
	for i in range(2, 2 * k + 1):
		f2[i] += f2[i - 1]
		f3[i] += f3[i - 1]
	ans = int(1000000000.0)
	for i in range(1, 2 * k + 1):
		ans = min(ans, n // 2 - f1[i] + f2[i - 1] + f3[2 * k] - f3[i])
	print(ans)


import heapq
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	q = []
	for i in range(n):
		heapq.heappush(q, arr[i])
	pos = 0
	cnt = 0
	ans = []
	while pos < n - 2:
		tmp = heapq.heappop(q)
		if arr[pos] == tmp:
			pos += 1
			continue
		else:
			tpos = pos + arr[pos:].index(tmp)
			while tpos - pos >= 2:
				cnt += 1
				tpos -= 2
				ans.append(tpos + 1)
				(arr[tpos], arr[tpos + 1], arr[tpos + 2]) = (arr[tpos + 2], arr[tpos], arr[tpos + 1])
			if tpos - pos == 1:
				cnt += 2
				tpos -= 1
				ans.append(tpos + 1)
				ans.append(tpos + 1)
				(arr[tpos], arr[tpos + 1], arr[tpos + 2]) = (arr[tpos + 1], arr[tpos + 2], arr[tpos])
			pos += 1
	if arr[n - 2] <= arr[n - 1]:
		print(cnt)
		print(*ans)
	else:
		ttpos = -1
		for i in range(n - 2, -1, -1):
			if arr[i] == arr[i + 1]:
				ttpos = i
				break
		if ttpos == -1:
			cnt += 1
			ans.append(n - 2)
			(arr[n - 3], arr[n - 2], arr[n - 1]) = (arr[n - 1], arr[n - 3], arr[n - 2])
			if arr[n - 3] <= arr[n - 2] <= arr[n - 1]:
				print(cnt)
				print(*ans)
			else:
				cnt += 1
				ans.append(n - 2)
				(arr[n - 3], arr[n - 2], arr[n - 1]) = (arr[n - 1], arr[n - 3], arr[n - 2])
				if arr[n - 3] <= arr[n - 2] <= arr[n - 1]:
					print(cnt)
					print(*ans)
				else:
					print(-1)
		else:
			cnt += 2
			ans.append(ttpos + 1)
			ans.append(ttpos + 1)
			(arr[ttpos], arr[ttpos + 1], arr[ttpos + 2]) = (arr[ttpos + 1], arr[ttpos + 2], arr[ttpos])
			q = []
			for i in range(n):
				heapq.heappush(q, arr[i])
			pos = 0
			while pos < n - 2:
				tmp = heapq.heappop(q)
				if arr[pos] == tmp:
					pos += 1
					continue
				else:
					tpos = pos + arr[pos:].index(tmp)
					while tpos - pos >= 2:
						cnt += 1
						tpos -= 2
						ans.append(tpos + 1)
						(arr[tpos], arr[tpos + 1], arr[tpos + 2]) = (arr[tpos + 2], arr[tpos], arr[tpos + 1])
					if tpos - pos == 1:
						cnt += 2
						tpos -= 1
						ans.append(tpos + 1)
						ans.append(tpos + 1)
						(arr[tpos], arr[tpos + 1], arr[tpos + 2]) = (arr[tpos + 1], arr[tpos + 2], arr[tpos])
					pos += 1
			print(cnt)
			print(*ans)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	ma = max(a[0], a[-1])
	mi = min(a[0], a[-1])
	start = a[0] + a[-1] - (ma - 1)
	end = a[0] + a[-1] + (k - mi)
	s = []
	e = []
	s.append(start)
	e.append(end)
	events = [0 for _ in range(2 * k + 2)]
	events[start] += 1
	events[end + 1] -= 1
	for i in range(1, len(a) // 2):
		ma = max(a[i], a[n - i - 1])
		mi = min(a[i], a[n - i - 1])
		s.append(a[i] + a[n - i - 1] - (ma - 1))
		e.append(a[i] + a[n - i - 1] + (k - mi))
		events[s[-1]] += 1
		events[e[-1] + 1] -= 1
	sums = {}
	for i in range(0, len(a) // 2):
		if a[i] + a[n - i - 1] not in sums:
			sums[a[i] + a[n - i - 1]] = 0
		sums[a[i] + a[n - i - 1]] += 1
	prefix = [0 for _ in range(2 * k + 1)]
	minimum = 10000000000.0
	for i in range(2, 2 * k + 1):
		prefix[i] = prefix[i - 1] + events[i]
		minimum = min(minimum, (n // 2 - prefix[i]) * 2 + (prefix[i] - sums.get(i, 0)))
	print(minimum)


import bisect
import collections
t = int(input())
for case_num in range(t):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	x = [a[i] + a[n - 1 - i] for i in range(n // 2)]
	x = collections.Counter(x)
	y = [min(a[i], a[n - 1 - i]) + 1 for i in range(n // 2)]
	z = [max(a[i], a[n - 1 - i]) + k for i in range(n // 2)]
	y.sort()
	z.sort()
	ans = n // 2
	for i in range(2, 2 * k + 1):
		zero = x[i]
		two = bisect.bisect_left(z, i) + n // 2 - bisect.bisect_right(y, i)
		one = n // 2 - zero - two
		ans = min(ans, one + two * 2)
	print(ans)


t = int(input())
import random
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	c = [0] * (k + 1)
	e = [0] * (k + 1)
	d = {}
	for i in range(n // 2):
		c[min(l[i], l[n - 1 - i])] += 1
		e[max(l[i], l[n - 1 - i])] += 1
		try:
			d[l[i] + l[n - 1 - i]] += 1
		except:
			d[l[i] + l[n - 1 - i]] = 1
	for i in range(1, k + 1):
		c[i] += c[i - 1]
		e[i] += e[i - 1]
	ans = n
	for i in range(2, 2 * k + 1):
		if i <= k:
			x = c[i - 1]
		else:
			x = e[k] - e[i - k - 1]
		try:
			x = x - d[i]
		except:
			pass
		if i > k:
			x = x + (n // 2 - e[k] + e[i - k - 1]) * 2
		else:
			x = x + (n // 2 - c[i - 1]) * 2
		ans = min(ans, x)
	print(ans)


from collections import defaultdict

def solve(n, k, arr):
	ans = n
	memo = defaultdict(int)
	prefix = [0] * (2 * k + 2)
	for i in range(n // 2):
		(x, y) = (arr[i], arr[n - i - 1])
		prefix[min(x, y) + 1] += 1
		prefix[max(x, y) + k + 1] -= 1
		memo[x + y] += 1
	for i in range(1, 2 * k + 2):
		prefix[i] += prefix[i - 1]
	for i in range(2, 2 * k + 1):
		ans = min(ans, prefix[i] - memo[i] + (n // 2 - prefix[i]) * 2)
	print(ans)
for _ in range(int(input())):
	(n, k) = input().strip().split()
	arr = list(map(int, input().strip().split()))
	solve(int(n), int(k), arr)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	prefix = [0] * (2 * k + 10)
	pairArr = [[min(arr[i], arr[n - i - 1]), max(arr[i], arr[n - i - 1])] for i in range(n // 2)]
	keep = defaultdict(int)
	for i in range(len(pairArr)):
		l = pairArr[i][0] + 1
		r = pairArr[i][1] + k
		keep[pairArr[i][0] + pairArr[i][1]] += 1
		prefix[l] += 1
		prefix[r + 1] -= 1
	s = 0
	for i in range(2 * k + 10):
		s += prefix[i]
		prefix[i] = s
	ans = float('inf')
	which_x = 0
	for x in range(2, 2 * k + 1):
		c0 = keep[x]
		c1 = prefix[x] - c0
		c2 = n // 2 - c1 - c0
		count = c2 * 2 + c1
		if ans > count:
			ans = count
			which_x = x
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cnt = [0] * (k * 2 + 1)
	pref = [0] * (k * 2 + 1 + 1)
	prefpref = [0] * (k * 2 + 1 + 1)
	for i in range(n // 2):
		cnt[a[i] + a[-i - 1]] += 1
		pref[min(a[i], a[-i - 1]) + 1] += 1
		pref[max(a[i], a[-i - 1]) + k + 1] -= 1
	prefpref[0] = pref[0]
	for i in range(1, k * 2 + 1):
		prefpref[i] = prefpref[i - 1] + pref[i]
	ans = n + 1
	for i in range(2, 2 * k + 1):
		ans = min(ans, prefpref[i] - cnt[i] + (n // 2 - prefpref[i]) * 2)
	print(ans)


import sys
input = sys.stdin.readline
from itertools import accumulate
t = int(input())
for tests in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	ANS = [0] * (k * 2 + 3)
	for i in range(n // 2):
		(x, y) = (A[i], A[n - 1 - i])
		if x > y:
			(x, y) = (y, x)
		ANS[x + 1] -= 1
		ANS[y + k + 1] += 1
		ANS[x + y] -= 1
		ANS[x + y + 1] += 1
	total = 0
	best = float('inf')
	for v in ANS:
		total += v
		best = min(best, total)
	print(n + best)


q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	s = [int(i) for i in input().split()]
	cost0 = [0] * (2 * k + 1)
	cost1 = [0] * (2 * k + 1)
	for i in range(n // 2):
		cost0[s[i] + s[n - i - 1]] += 1
		cost1[min(s[i], s[n - i - 1]) + 1] += 1
		if max(s[i], s[n - i - 1]) < k:
			cost1[max(s[i], s[n - i - 1]) + k + 1] -= 1
	for i in range(3, 2 * k + 1):
		cost1[i] += cost1[i - 1]
	ans = n
	for x in range(2, 2 * k + 1):
		cost = n - cost1[x] - cost0[x]
		ans = min(ans, cost)
	print(ans)


def swap(i, j):
	(arr[i], arr[j]) = (arr[j], arr[i])

def inversion(li):
	n = len(li)
	inversions = 0
	for i in range(n):
		for j in range(i + 1, n):
			if li[j] < li[i]:
				inversions += 1
	return inversions

def right_shift(i):
	(arr[i], arr[i + 1], arr[i + 2]) = [arr[i + 2], arr[i], arr[i + 1]]
t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	arr = [int(i) for i in l]
	arr1 = list(arr)
	lfi = []
	lo = []
	for i in range(n):
		lo.append((arr[i], i))
	lo.sort()
	hashi = dict()
	for i in range(n):
		hashi[lo[i][1]] = i + 1
	arr = []
	for i in range(n):
		arr.append(hashi[i])
	poss = 1
	if inversion(arr) % 2:
		for i in range(n):
			for j in range(i + 1, n):
				if arr1[i] == arr1[j]:
					swap(i, j)
					poss = 0
					break
			if poss == 0:
				break
	z = list(arr)
	z.sort()
	for j in range(n):
		for i in range(n - 2 - j):
			maxa = max(arr[i], arr[i + 1], arr[i + 2])
			if maxa == arr[i + 2]:
				continue
			elif maxa == arr[i + 1]:
				lfi.append(i)
				right_shift(i)
			else:
				lfi.append(i)
				lfi.append(i)
				right_shift(i)
				right_shift(i)
	if arr == z:
		print(len(lfi))
		for i in lfi:
			print(i + 1, end=' ')
		print()
	else:
		print(-1)


from itertools import accumulate

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def sgn(x):
	if x > 0:
		return '+'
	else:
		return '-'

def solve(n, k, a):
	h = [0] * (2 * k + 5)
	for i in range(n // 2):
		j = n - i - 1
		h[0] += 2
		h[min(a[i], a[j]) + 1] -= 1
		h[a[i] + a[j]] -= 1
		h[a[i] + a[j] + 1] += 1
		h[max(a[i], a[j]) + k + 1] += 1
	pref = list(accumulate(h))
	return min(pref)

def main():
	T = int(input())
	for tt in range(T):
		(n, k) = invr()
		a = list(invr())
		print(solve(n, k, a))
main()


import bisect
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	ans = n // 2
	maxes = [0] * ans
	mines = [0] * ans
	summes = []
	count_summes = {}
	for i in range(n // 2):
		count_summes[a[i] + a[n - i - 1]] = 0
	for i in range(n // 2):
		maxes[i] = max(a[i], a[n - i - 1])
		mines[i] = min(a[i], a[n - i - 1])
		summes.append(a[i] + a[n - i - 1])
		count_summes[a[i] + a[n - i - 1]] += 1
	maxes.sort()
	mines.sort()
	for i in range(len(summes)):
		ans_now = 0
		s_now = summes[i]
		max_s = s_now - k
		min_s = s_now - 1
		first = 2 * (n // 2 - bisect.bisect_right(mines, min_s))
		second = 2 * bisect.bisect_left(maxes, max_s)
		ost = n // 2 - first // 2 - second // 2 - count_summes[s_now]
		ans = min(ans, ost + first + second)
	print(ans)


def solve(n, k, a):
	maxv = {i: 0 for i in range(2, 2 * k + 1)}
	minv = {i: 0 for i in range(2, 2 * k + 1)}
	exactv = {i: 0 for i in range(2, 2 * k + 1)}
	for i in range(n // 2):
		(x, y) = (a[i], a[-1 - i])
		(x, y) = (min(x, y), max(x, y))
		exactv[x + y] += 1
		minv[x + 1] += 1
		maxv[y + k] += 1
	rs = 0
	for i in range(2, 2 * k + 1):
		rs += minv[i]
		minv[i] = rs
	rs = 0
	for i in range(2 * k, 1, -1):
		rs += maxv[i]
		maxv[i] = rs
	return min([n // 2 - minv[i] + (n // 2 - maxv[i]) + (n // 2 - exactv[i]) for i in range(2, 2 * k + 1)])
t = int(input().strip())
for _ in range(t):
	(n, k) = list(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))
	print(solve(n, k, a))


from sys import stdin
from functools import lru_cache, cmp_to_key
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
from collections import Counter, deque
from bisect import bisect_left, bisect_right

def solver():
	line = stdin.readline()
	[n, k] = [*map(int, line.split())]
	line = stdin.readline()
	nums = [*map(int, line.split())]
	(mn, mx, sum) = ([], [], [])
	for i in range(n // 2):
		mn.append(min(nums[i], nums[n - 1 - i]))
		mx.append(max(nums[i], nums[n - 1 - i]))
		sum.append(nums[i] + nums[n - 1 - i])
	mn.sort()
	mx.sort()
	cnt = [n // 2] * (2 * k + 1)
	for i in range(k + 1):
		pos = bisect_left(mn, i)
		cnt[i] += n // 2 - pos
	for i in range(k + 1, k * 2 + 1):
		pos = bisect_left(mx, i - k)
		cnt[i] += pos
	for i in sum:
		cnt[i] -= 1
	res = min(cnt)
	print('{}'.format(res))

def main():
	T = int(stdin.readline())
	for case_num in range(T):
		solver()
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	freq = {i: 0 for i in range(2, 2 * k + 1)}
	pref = [0] * (2 * k + 10)
	for i in range(n // 2):
		(l, r) = (min(a[i], a[n - 1 - i]), max(a[i], a[n - 1 - i]))
		freq[l + r] += 1
		pref[l + 1] += 1
		pref[r + k + 1] -= 1
	ans = n
	for i in range(2, 2 * k + 1):
		pref[i] += pref[i - 1]
		ans = min(ans, pref[i] - freq[i] + 2 * (n // 2 - pref[i]))
	print(ans)


import sys
from collections import Counter

def I():
	return list(map(int, input().split()))

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a

def calc(x):
	c = 0
	n = len(arr)
	for i in range(n // 2):
		if sumarr[i] != x:
			m = max(arr[i], arr[n - i - 1])
			if sumarr[i] < x:
				m = min(arr[i], arr[n - i - 1])
				m += x - sumarr[i]
				if m > k:
					c += 2
				else:
					c += 1
			else:
				m = max(arr[i], arr[n - i - 1])
				m -= sumarr[i] - x
				if m < 0:
					c += 2
				else:
					c += 1
	return c
for __ in range(int(input())):
	(n, k) = I()
	arr = I()
	sumarr = [0] * (n // 2)
	for i in range(n // 2):
		sumarr[i] = arr[i] + arr[n - i - 1]
	c = Counter(sumarr)
	prefarr = [0] * (2 * k + 2)
	for i in range(n // 2):
		(a, b) = (max(arr[i], arr[n - i - 1]), min(arr[i], arr[n - i - 1]))
		r = a + k
		l = b + 1
		prefarr[l] += 1
		prefarr[r + 1] -= 1
	minans = n
	for i in range(1, 2 * k + 1):
		prefarr[i] += prefarr[i - 1]
		minans = min(minans, prefarr[i] - c.get(i, 0) + 2 * (n // 2 - prefarr[i]))
	print(minans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

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

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		n = N()
		arr = RLL()
		sarr = sorted(arr)
		res = []

		def swap(i):
			res.append(i + 1)
			(arr[i], arr[i + 1], arr[i + 2]) = (arr[i + 2], arr[i], arr[i + 1])
		for i in range(n - 2):
			now = arr[i]
			if now == sarr[i]:
				continue
			for j in range(i + 1, n):
				if arr[j] == sarr[i]:
					ind = j
					while ind - 2 >= i:
						swap(ind - 2)
						ind -= 2
					if ind != i:
						swap(i)
						swap(i)
		for i in range(n - 1, 1, -1):
			now = arr[i]
			if now == sarr[i]:
				continue
			for j in range(i - 1, -1, -1):
				if arr[j] == sarr[i]:
					ind = j
					while ind + 2 <= i:
						swap(ind)
						swap(ind)
						ind += 2
					if ind != i:
						swap(ind - 1)
		if sarr != arr:
			print(-1)
		else:
			print(len(res))
			print(*res)
main()


t = int(input())
from copy import deepcopy

def solve():
	d = [-1] * n
	for i in range(n):
		(x, y) = l2[i]
		d[y] = i
	ans = []
	count = 0
	for i in range(n - 1, 1, -1):
		y = d.index(i)
		while y < i:
			count += 1
			if y == i - 1:
				ans.append(y)
				(d[y - 1], d[y], d[y + 1]) = (d[y + 1], d[y - 1], d[y])
			else:
				ans.append(y + 1)
				(d[y], d[y + 1], d[y + 2]) = (d[y + 2], d[y], d[y + 1])
			y += 1
	if d[0] <= d[1] <= d[2]:
		print(count)
		print(*ans)
		return True
	else:
		check = False
		c = 0
		while c < 3:
			ans.append(1)
			(d[0], d[1], d[2]) = (d[2], d[0], d[1])
			count += 1
			c += 1
			if d[0] <= d[1] <= d[2]:
				check = True
				break
		if check:
			print(count)
			print(*ans)
			return True
		else:
			return False
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l2 = sorted([[x, i] for (i, x) in enumerate(l)])
	if solve() == False:
		for i in range(n - 1):
			if l2[i][0] == l2[i + 1][0]:
				(l2[i][1], l2[i + 1][1]) = (l2[i + 1][1], l2[i][1])
				break
		if solve() == False:
			print(-1)


import os
import sys
from io import BytesIO, IOBase

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		L = list(map(int, input().split()))
		size = 2 * k + 1
		count = [0] * size
		ans = [0] * size
		(i, j) = (0, n - 1)
		while i < j:
			count[L[i] + L[j]] += 1
			i += 1
			j -= 1
		(i, j) = (0, n - 1)
		while i < j:
			(a, b) = (L[i], L[j])
			ans[min(a, b) + 1] += 1
			try:
				ans[max(a, b) + k + 1] -= 1
			except IndexError:
				pass
			i += 1
			j -= 1
		for i in range(2, size):
			ans[i] += ans[i - 1]
		for i in range(2, size):
			ans[i] -= count[i]
		for i in range(2, size):
			ans[i] += 2 * (n // 2 - (count[i] + ans[i]))
		print(min(ans[2:]))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = lambda s: self.buffer.write(s.encode()) if self.writable else None

	def read(self):
		if self.buffer.tell():
			return self.buffer.read().decode('ascii')
		return os.read(self._fd, os.fstat(self._fd).st_size).decode('ascii')

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline().decode('ascii')

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

def print(*args, sep=' ', end='\n', file=sys.stdout, flush=False):
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(end)
	if flush:
		file.flush()
(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.setrecursionlimit(10000)
main()


from sys import stdin, stdout

def cyclic_shifts_sorting(n, a):
	dic = {}
	dupi = -1
	dupj = -1
	for i in range(n):
		a[i] *= 1000
		if a[i] in dic:
			k = a[i]
			a[i] += dic[k][0]
			dic[k][0] += 1
			if dupi == -1:
				dupi = dic[k][1]
				dupj = i
		else:
			dic[a[i]] = [1, i]
	iv = 0
	for i in range(n):
		for j in range(i + 1, n):
			if a[i] > a[j]:
				iv += 1
	if iv % 2 == 1:
		if dupi == -1:
			return [-1]
		else:
			tmp = a[dupi]
			a[dupi] = a[dupj]
			a[dupj] = tmp
	sa = sorted(a)
	res = []
	for i in range(n):
		if sa[i] == a[i]:
			continue
		idx = -1
		for j in range(n):
			if a[j] == sa[i]:
				idx = j
				break
		while idx >= i + 2:
			tmp = a[idx]
			a[idx] = a[idx - 1]
			a[idx - 1] = a[idx - 2]
			a[idx - 2] = tmp
			res.append(idx - 2 + 1)
			idx -= 2
		if idx > i:
			tmp = a[idx]
			a[idx] = a[idx + 1]
			a[idx + 1] = a[idx - 1]
			a[idx - 1] = tmp
			res.append(idx - 1 + 1)
			res.append(idx - 1 + 1)
			idx -= 1
	return [len(res), res]
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	res = cyclic_shifts_sorting(n, a)
	stdout.write(str(res[0]) + '\n')
	if res[0] > -1:
		stdout.write(' '.join(map(str, res[1])) + '\n')


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def findmin(x, y):
	if x < y:
		return x
	return y

def findmax(x, y):
	if x > y:
		return x
	return y
t = inp()
for i in range(0, t):
	(n, k) = invr()
	a = list(invr())
	(min, max) = (0, 0)
	f = [0] * (2 * k + 2)
	cnt = [0] * (2 * k + 1)
	for j in range(0, int(n / 2)):
		cnt[a[j] + a[n - j - 1]] = cnt[a[j] + a[n - j - 1]] + 1
		min = findmin(a[j], a[n - j - 1]) + 1
		max = findmax(a[j], a[n - j - 1]) + k
		f[min] = f[min] + 1
		f[max + 1] = f[max + 1] - 1
	for j in range(1, 2 * k + 1):
		f[j] = f[j] + f[j - 1]
	result = 999999
	for l in range(2, 2 * k + 1):
		q = f[l] - cnt[l] + (n / 2 - f[l]) * 2
		if result > q:
			result = q
	print(int(result))


def g(A, i, y, move):
	n = min(i, y - 2)
	(A[n - 1], A[n], A[n + 1]) = (A[n + 1], A[n - 1], A[n])
	move.append(max(1, n))

def f(A, x, y, move):
	i = A.index(x) + 1
	while i < y:
		g(A, i, y, move)
		i += 1
for tc in range(int(input())):
	n = int(input())
	A = input().split(' ')
	B = []
	S = []
	Amove = []
	Bmove = []
	for i in range(n):
		A[i] = int(A[i])
		B.append(A[i])
		S.append(A[i])
	S.sort()
	dupin = -1
	for i in range(n - 1):
		if S[i] == S[i + 1]:
			dupin = i
			break
	if dupin == -1:
		for i in range(n - 2):
			f(A, S[n - i - 1], n - i, Amove)
		if A[0] > A[1]:
			print(-1)
		else:
			print(len(Amove))
			for i in Amove:
				print(i, end=' ')
			print()
	else:
		for i in range(n - 2):
			f(A, S[n - i - 1], n - i, Amove)
		if A[0] <= A[1]:
			print(len(Amove))
			for i in Amove:
				print(i, end=' ')
			print()
			continue
		elif A[0] == A[2]:
			Amove.append(1)
			Amove.append(1)
			print(len(Amove))
			for i in Amove:
				print(i, end=' ')
			print()
			continue
		else:
			for i in range(n - 2):
				f(B, S[n - i - 1], n - i, Bmove)
				if n - i - 1 == dupin:
					g(B, n - i - 1, n, Bmove)
					g(B, n - i - 2, n, Bmove)
			print(len(Bmove))
			for i in Bmove:
				print(i, end=' ')
			print()


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	s = [0] * (2 * k + 2)
	for i in range(n // 2):
		x = a[i]
		y = a[n - i - 1]
		s[2] += 2
		s[min(x, y) + 1] -= 1
		s[max(x, y) + k + 1] += 1
		s[x + y] -= 1
		s[x + y + 1] += 1
	for i in range(2, 2 * k + 2):
		s[i] += s[i - 1]
	print(min(s[2:]))


import sys
from itertools import accumulate

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, K) = MAP()
	A = LIST()
	B = [()] * (N // 2)
	for i in range(N // 2):
		j = N - i - 1
		if A[i] < A[j]:
			B[i] = (A[i], A[j])
		else:
			B[i] = (A[j], A[i])
	imos = [0] * (K * 2 + 2)
	imos[1] = 2 * (N // 2)
	imos[-1] = -2 * (N // 2)
	for (a, b) in B:
		sm = a + b
		imos[sm] -= 1
		imos[sm + 1] += 1
		lo = a + 1
		hi = K + b
		imos[lo] -= 1
		imos[hi + 1] += 1
	imos = list(accumulate(imos))
	ans = min(imos[1:K * 2 + 1])
	print(ans)


import sys

def solve():
	(n, k) = [int(x) for x in input().split()]
	li = [int(x) for x in input().split()]
	zero_changes = [0] * (2 * k + 1)
	for i in range(n // 2):
		zero_changes[li[i] + li[n - i - 1]] += 1
	one_changes = [0] * (2 * k + 2)
	for i in range(n // 2):
		maxp = max(li[i], li[n - i - 1]) + k
		minp = min(li[i], li[n - i - 1]) + 1
		one_changes[minp] += 1
		one_changes[maxp + 1] -= 1
	for i in range(3, 2 * k + 1):
		one_changes[i] += one_changes[i - 1]
	minm = sys.maxsize
	for i in range(2, 2 * k + 1):
		zero = zero_changes[i]
		one = one_changes[i] - zero
		two = n // 2 - one - zero
		total_cost = 2 * two + 1 * one + 0 * zero
		minm = min(minm, total_cost)
	print(minm)
t = int(input())
for i in range(t):
	solve()


t = int(input())
for x in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr_0 = [0 for i in range(2 * k + 1)]
	arr_1 = [0 for i in range(2 * k + 2)]
	for i in range(n // 2):
		min_no = min(arr[i], arr[n - i - 1])
		max_no = max(arr[i], arr[n - i - 1])
		arr_0[min_no + max_no] += 1
		l_ind = min_no + 1
		r_ind = max_no + k
		arr_1[l_ind] += 1
		arr_1[r_ind + 1] -= 1
	for i in range(2, 2 * k + 2):
		arr_1[i] += arr_1[i - 1]
	ans = 10000000
	for i in range(2, 2 * k + 1):
		cur_ans = arr_1[i] - arr_0[i] + 2 * (n // 2 - arr_1[i])
		if cur_ans < ans:
			ans = cur_ans
	print(ans)


import os
import sys
from io import BytesIO, IOBase
from bisect import bisect_left, bisect_right
import threading
from collections import Counter, defaultdict
arr = []

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		a = arr.copy()
		a.sort()
		mis = 0
		cnt = [0] * 501
		for i in arr:
			cnt[i] += 1
		b = True
		for i in cnt:
			if i > 1:
				b = False
		for i in range(n):
			for j in range(i + 1, n):
				if arr[j] < arr[i]:
					mis += 1
		if mis % 2 == 1 and b:
			print(-1)
		else:
			ans = []
			st = n - 1
			while st > 1:
				ma_ = max(arr)
				ind = arr.index(ma_)
				for i in range(ind, st - 1):
					(arr[i], arr[i + 1], arr[i + 2]) = (arr[i + 2], arr[i], arr[i + 1])
					ans.append(i)
				if arr[st] != ma_:
					(arr[st - 2], arr[st - 1], arr[st]) = (arr[st], arr[st - 2], arr[st - 1])
					ans.append(st - 2)
				arr[st] = -1
				st -= 1
			if arr[0] > arr[1]:
				i = 1
				while i + 2 < len(a) and a[i] != a[i - 1]:
					ans.append(i)
					ans.append(i - 1)
					(a[i + 1], a[i + 2]) = (a[i + 2], a[i + 1])
					i += 2
					if i < n - 1 and a[i + 1] == a[i - 1]:
						ans.append(i - 1)
						ans.append(i - 1)
						break
			for i in range(len(ans)):
				ans[i] += 1
			print(len(ans))
			print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

def solve(N, K, A):
	M = 2 * K + 1
	x = [0 for _ in range(M)]
	add = [0 for _ in range(M)]
	minus = [0 for _ in range(M)]
	wc = collections.defaultdict(int)
	for i in range(N // 2):
		(a, b) = (A[i], A[N - i - 1])
		wc[a + b] += 1
		(s, t) = (min(a, b) + 1, max(a, b) + K + 1)
		if s < M:
			add[s] += 1
		if t < M:
			minus[t] += 1
	s = 0
	for i in range(M):
		s += add[i]
		s -= minus[i]
		x[i] = s
	ans = N
	for target in range(2, M):
		one = x[target] - wc[target]
		two = N // 2 - wc[target] - one
		ans = min(ans, one + 2 * two)
	return ans
T = int(input())
ans = []
for ti in range(T):
	(N, K) = map(int, input().split())
	A = [int(x) for x in input().split()]
	ans.append(solve(N, K, A))
print('\n'.join(map(str, ans)))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	lowpen = [0 for j in range(k)]
	highpen = [0 for j in range(k)]
	Reward = [0 for j in range(2 * k - 1)]
	for j in range(0, n // 2):
		a = min(nums[j], nums[n - j - 1])
		b = max(nums[j], nums[n - j - 1])
		lowpen[a - 1] += 1
		highpen[b - 1] += 1
		Reward[a + b - 2] += 1
	for j in range(1, k):
		lowpen[k - 1 - j] += lowpen[k - j]
		highpen[j] += highpen[j - 1]
	for j in range(1, k):
		Reward[j - 1] -= lowpen[j]
	for j in range(k, 2 * k - 1):
		Reward[j] -= highpen[j - k]
	print(n // 2 - max(Reward))


from collections import defaultdict
n = int(input())
for i in range(n):
	(m, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	h = defaultdict(int)
	pair = []
	(s, e) = (0, len(nums) - 1)
	while s < e:
		h[nums[s] + nums[e]] += 1
		pair.append((min(nums[s], nums[e]), max(nums[s], nums[e])))
		s += 1
		e -= 1
	p = [0] * (2 * k + 1)
	for (s, e) in pair:
		new_range = (s + 1, e + k)
		p[new_range[0]] += 1
		if new_range[1] + 1 < len(p):
			p[new_range[1] + 1] -= 1
	for i in range(1, len(p)):
		p[i] += p[i - 1]
	final = []
	for i in range(2, 2 * k + 1):
		changes = len(pair)
		(zero, one, two) = (0, 0, 0)
		if i in h:
			zero += h[i]
			changes -= zero
		if changes:
			one = p[i] - zero
			changes -= one
		if changes:
			two = changes
		final.append(2 * two + one)
	print(min(final))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	x = [0 for i in range(2 * k + 2)]
	for i in range(n // 2):
		x[k + max(l[i], l[n - 1 - i]) + 1] -= 1
		x[1 + min(l[i], l[n - 1 - i])] += 1
	low = 0
	high = 0
	maxfreq = 0
	for i in range(1, 2 * k + 1):
		x[i] += x[i - 1]
	for i in range(1, 2 * k + 1):
		if x[i] > maxfreq:
			maxfreq = x[i]
			(low, high) = (i, i)
		elif x[i] == maxfreq:
			high = i
	d = {}
	maxchanges = 0
	for i in range(n // 2):
		s = l[i] + l[n - 1 - i]
		if s in d:
			d[s] += 1
		else:
			d[s] = 1
		changes = d[s] + x[s]
		if changes > maxchanges:
			maxchanges = changes
	print(n - max(maxchanges, max(x)))


cnt = [0] * int(400000.0 + 5)
f = [0] * int(400000.0 + 5)
q = int(input())
while q > 0:
	q -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n // 2):
		j = n - 1 - i
		if a[i] > a[j]:
			temp = a[i]
			a[i] = a[j]
			a[j] = temp
		cnt[max(a[i] + 1, 2)] -= 1
		cnt[min(a[j] + k + 1, 2 * k + 1)] += 1
		f[a[i] + a[j]] += 1
	temp = n
	res = int(2000000000.0)
	for i in range(2, 2 * k + 1):
		temp += cnt[i]
		res = min(res, temp - f[i])
	for i in range(n // 2):
		j = n - 1 - i
		if a[i] > a[j]:
			swap(a[i], a[j])
		cnt[max(a[i] + 1, 2)] = 0
		cnt[min(a[j] + k + 1, 2 * k + 1)] = 0
		f[a[i] + a[j]] = 0
	print(res)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	Arr = [0] * (2 * k + 2)
	for i in range(n // 2):
		mi = min(l[i], l[n - i - 1])
		ma = max(l[i], l[n - i - 1])
		Arr[mi + ma] -= 1
		Arr[1] += 2
		Arr[mi + 1] -= 1
		Arr[mi + ma + 1] += 1
		Arr[ma + k + 1] += 1
	ans = 2e+18
	for t in range(1, len(Arr)):
		Arr[t] = Arr[t] + Arr[t - 1]
		ans = min(ans, Arr[t])
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	OUT = [n // 2] * (2 * k + 2)
	extraL = [0] * (2 * k + 2)
	extraR = [0] * (2 * k + 2)
	for i in range(n // 2):
		left = l[i]
		right = l[n - 1 - i]
		OUT[left + right] -= 1
		extraL[min(left, right)] += 1
		extraR[max(left, right) + k + 1] += 1
	curr = 0
	for i in range(2 * k + 2):
		curr += extraR[i]
		extraR[i] = curr
	curr = 0
	for i in range(2 * k + 1, -1, -1):
		curr += extraL[i]
		extraL[i] = curr
	for i in range(2 * k + 2):
		OUT[i] += extraL[i] + extraR[i]
	print(min(OUT))


for i in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	cnt = [0 for i in range(2 * k + 5)]
	pref = cnt[:]
	for i in range(n // 2):
		cnt[arr[i] + arr[n - i - 1]] += 1
		mnSum = min(arr[i], arr[n - i - 1]) + 1
		mxSum = max(arr[i], arr[n - i - 1]) + k
		pref[mnSum] += 1
		pref[mxSum + 1] -= 1
	for i in range(1, len(pref)):
		pref[i] += pref[i - 1]
	ans = n
	for i in range(len(pref)):
		cur = pref[i] - cnt[i] + (n // 2 - pref[i]) * 2
		ans = min(ans, cur)
	print(ans)


t = int(input())

def oco(l):
	d = {}
	for el in l:
		if el in d:
			d[el] += 1
		else:
			d[el] = 1
	return d
for test in range(t):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	psum = [a[i] + a[n - i - 1] for i in range(len(a) // 2)]
	pmax = [k + max(a[i], a[n - i - 1]) for i in range(len(a) // 2)]
	pmax.sort()
	pmin = [1 + min(a[i], a[n - i - 1]) for i in range(len(a) // 2)]
	pmin.sort()
	di = oco(psum)
	itma = 0
	itmi = 0
	ans = [0 for i in range(2 * k - 1)]
	for i in range(len(ans)):
		while itma < len(pmax):
			if pmax[itma] >= i + 2:
				break
			itma += 1
		while itmi < len(pmin):
			if pmin[itmi] > i + 2:
				break
			itmi += 1
		ans[i] = n + itma - itmi
		if i + 2 in di:
			ans[i] -= di[i + 2]
	print(min(ans))


import sys
input = sys.stdin.readline

def bs(l, target, n):
	low = 0
	high = n
	ans = -1
	while low <= high:
		mid = low + (high - low) // 2
		if l[mid] <= target:
			ans = max(ans, mid)
			low = mid + 1
		else:
			high = mid - 1
	return ans
t = int(input())
for r in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	start = []
	end = []
	i = 0
	j = n - 1
	while i < j:
		start.append(min(l[i], l[j]) + 1)
		end.append(max(l[i], l[j]) + k)
		try:
			d[l[i] + l[j]] += 1
		except:
			d[l[i] + l[j]] = 1
		i += 1
		j -= 1
	start.sort()
	end.sort()
	mini = 999999999999999
	for i in range(1, 2 * k + 1):
		a = bs(start, i, len(start) - 1) + 1
		b = bs(end, i - 1, len(end) - 1) + 1
		one = a - b
		zero = 0
		try:
			zero = d[i]
		except:
			pass
		twos = n // 2 - one
		ans = twos * 2 + (one - zero)
		mini = min(mini, ans)
	print(mini)


import sys
input = sys.stdin.buffer.readline
import collections

def solve(n, k, arr):
	d = collections.defaultdict(int)
	for i in range(n // 2):
		t = arr[i] + arr[n - 1 - i]
		d[t] += 1
	count_list = sorted(set(d.values()))
	ans = float('inf')
	for i in count_list:
		upper_near_mid_v = float('inf')
		v1 = 0
		lower_near_mid_v = float('inf')
		v2 = 0
		for j in d:
			if d[j] == i:
				if j > k:
					if j - k < upper_near_mid_v:
						upper_near_mid_v = j - k
						v1 = j
				elif k - j < lower_near_mid_v:
					lower_near_mid_v = k - j
					v2 = j

		def chk(v):
			if not v:
				return float('inf')
			t = 0
			for i in range(n // 2):
				temp = arr[i] + arr[n - 1 - i]
				if temp != v:
					max_v = max(arr[i], arr[n - 1 - i])
					min_v = min(arr[i], arr[n - 1 - i])
					if temp > v:
						if max_v - 1 >= temp - v:
							t += 1
						else:
							t += 2
					elif temp < v:
						if k - min_v >= v - temp:
							t += 1
						else:
							t += 2
			return t
		ans = min(ans, chk(v1), chk(v2))
	return min(ans, n // 2)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = solve(n, k, arr)
	print(ans)


import sys
input = sys.stdin.readline
import math
power = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
t = int(input())
for ijk in range(t):
	(n, k) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	(a1, a2) = ([0] * (2 * k + 2), [0] * (2 * k + 2))
	for i in range(len(arr) // 2):
		xy = min(arr[i], arr[-i - 1])
		yx = max(arr[i], arr[-i - 1])
		a1[xy] += 1
		if xy != arr[i] + arr[-i - 1] - 1:
			a1[arr[i] + arr[-i - 1] - 1] += 1
		a2[yx + k + 1] += 1
		if yx != arr[i] + arr[-i - 1] + 1:
			a2[arr[i] + arr[-i - 1] + 1] += 1
	(pref, suff) = ([0], [0])
	pref[0] = a1[-1]
	suff[0] = a2[0]
	for i in range(1, len(a1)):
		pref.append(a1[-i - 1] + pref[-1])
		suff.append(a2[i] + suff[-1])
	pref.reverse()
	mina = math.inf
	for i in range(1, 2 * k + 1):
		mina = min(mina, pref[i] + suff[i])
	sys.stdout.write(str(mina) + '\n')


T = int(input())
for _ in range(0, T):
	(n, k) = map(int, input().split())
	s = [int(x) for x in input().split()]
	dp = [0] * (2 * k + 5)
	tt = [0] * (2 * k + 5)
	for i in range(n // 2):
		a = min(s[i], s[n - i - 1])
		b = max(s[i], s[n - i - 1])
		low = a + 1
		high = min(b + k, 2 * k)
		dp[low] += 1
		dp[high + 1] -= 1
		dp[2] += 2
		dp[low] -= 2
		dp[high + 1] += 2
		dp[2 * k + 1] -= 2
		tt[a + b] -= 1
	ans = 2 * n
	for i in range(3, len(dp)):
		dp[i] += dp[i - 1]
	for i in range(2, 2 * k + 1):
		ans = min(ans, dp[i] + tt[i])
	print(ans)


t = int(input())
for _ in range(t):
	[n, k] = map(int, input().split())
	a = [*map(int, input().split())]
	cnt = [0] * (2 * k)
	intervals = [0] * (2 * k)
	for i in range(n // 2):
		v = a[i] + a[n - i - 1]
		cnt[v - 1] += 1
		ma = max(a[i], a[n - i - 1])
		mi = min(a[i], a[n - i - 1])
		intervals[mi] += 1
		if ma + k < 2 * k:
			intervals[ma + k] -= 1
	for i in range(1, 2 * k):
		intervals[i] += intervals[i - 1]
	ans = 1000000000.0
	for i in range(1, 2 * k):
		ans = min(ans, intervals[i] - cnt[i] + (n // 2 - intervals[i]) * 2)
	print(ans)


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
for _ in range(II()):

	def rot(top):
		(aa[top], aa[top + 1], aa[top + 2]) = (aa[top + 2], aa[top], aa[top + 1])
	n = II()
	aa = LI()
	bb = aa[:]
	bb.sort()
	ans = []
	for i in range(n - 2):
		j = i
		while aa[j] != bb[i]:
			j += 1
		while j > i:
			if i == j - 1:
				rot(i)
				rot(i)
				ans += [i + 1, i + 1]
				j = i
			else:
				rot(j - 2)
				ans += [j - 1]
				j -= 2
	if bb[-1] == aa[-1]:
		print(len(ans))
		print(*ans)
	else:
		for i in range(n - 3, -1, -1):
			rot(i)
			ans += [i + 1]
			if aa[i] == aa[i + 1]:
				print(len(ans))
				print(*ans)
				break
		else:
			print(-1)


for _ in range(int(input().strip())):
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	common_values = [0 for _ in range(2 * k + 2)]
	for i in range(n // 2):
		(a, b) = (nums[i], nums[n - 1 - i])
		common_values[a + b - max(a, b) + 1] -= 1
		common_values[a + b] -= 1
		common_values[a + b + 1] += 1
		common_values[a + b - min(a, b) + k + 1] += 1
	common_values[1] = n
	minimum = n
	for i in range(2, 2 * k + 1):
		common_values[i] += common_values[i - 1]
		minimum = min(minimum, common_values[i])
	print(minimum)


for t in range(int(input())):
	(n, k) = [int(j) for j in input().split()]
	l = [int(j) for j in input().split()]
	a = 0
	b = 0
	s = [0] * (2 * k + 1)
	t = [0] * (2 * k + 1)
	pre = [0] * (2 * k)
	suf = [0] * (2 * k)
	for i in range(n // 2):
		tmp = l[i] + l[n - i - 1]
		s[tmp] += 1
		pre[min(l[i], l[n - i - 1])] += 1
		suf[max(l[i], l[n - i - 1])] += 1
	for i in range(1, len(pre)):
		pre[i] += pre[i - 1]
		suf[i] += suf[i - 1]
	ans = n
	for sum_ in range(1, 2 * k + 1):
		tmp = suf[max(sum_ - k - 1, 0)] + n // 2 - s[sum_] + n // 2 - pre[max(sum_ - 1, 0)]
		ans = min(ans, tmp)
	print(ans)


for i in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	d = {}
	na = [0 for i in range(2 * k + 2)]
	for i in range(n // 2):
		d[arr[i] + arr[-1 - i]] = d.get(arr[i] + arr[-1 - i], 0) + 1
		na[max(arr[i], arr[-1 - i]) + k + 1] += -1
		na[min(arr[i], arr[-1 - i]) + 1] += 1
	for i in range(1, 2 * k + 2):
		na[i] += na[i - 1]
	key = list(d.keys())
	ans = n
	for i in key:
		ans = min(ans, na[i] + (n // 2 - na[i]) * 2 - d[i])
	print(min(ans, max(na) + (n // 2 - max(na)) * 2))


x = int(input())
for b in range(x):
	y = list(map(int, input().split()))
	z = list(map(int, input().split()))
	d = {}
	s1 = []
	s = sum(z) / (y[0] / 2)
	arr = [0 for i in range(int(y[1] * 2) + 2)]
	for a in range(y[0] // 2):
		s2 = z[a] + z[y[0] - a - 1]
		d[s2] = d.get(s2, 0) + 1
		arr[max(z[a], z[y[0] - a - 1]) + y[1] + 1] -= 1
		arr[min(z[a], z[y[0] - a - 1]) + 1] += 1
	for a in range(1, len(arr)):
		arr[a] += arr[a - 1]
	ans = 100000000000
	for each in d:
		ans = min(ans, arr[each] + (y[0] // 2 - arr[each]) * 2 - d[each])
	print(min(ans, max(arr) + (y[0] // 2 - max(arr)) * 2))


def update(bit, l, r, n, val):
	updatebit(bit, n, l, val)
	updatebit(bit, n, r + 1, -val)

def updatebit(bit, n, i, val):
	i += 1
	while i <= n:
		bit[i] += val
		i += i & -i

def get(bit, i):
	res = 0
	i += 1
	while i > 0:
		res += bit[i]
		i -= i & -i
	return res
t = int(input())
for tt in range(t):
	(N, K) = (int(i) for i in input().split())
	A = [int(i) for i in input().split()]
	pos = [0] * (2 * K + 2)
	n = len(pos) - 1
	for i in range(N // 2):
		(cur, mir) = (A[i], A[N - i - 1])
		L = R = cur + mir
		update(pos, L, R, n, -1)
		(L, R) = (min(cur, mir) + 1, max(cur, mir) + K)
		update(pos, L, R, n, -1)
	ans = N + min((get(pos, i) for i in range(2, n)))
	print(ans)


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	L = list(map(int, input().split()))
	prefix = [0] * (2 * K + 2)
	prefix[1] = N
	for i in range(N // 2):
		(x, y) = sorted((L[i], L[~i]))
		prefix[x + 1] -= 1
		prefix[x + y] -= 1
		prefix[x + y + 1] += 1
		prefix[y + K + 1] += 1
	for i in range(1, 2 * K + 2):
		prefix[i] += prefix[i - 1]
	print(min(prefix[2:]))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	li = [0] * (2 * k)
	pref = [0] * (2 * k)
	c = []
	if n == 2:
		print(0)
		continue
	for i in range(n // 2):
		li[a[i] + a[-i - 1] - 1] += 1
	for i in range(n // 2):
		(x, y) = (a[i], a[-i - 1])
		range_min = min(x, y) + 1
		range_max = max(x, y) + k
		pref[range_min - 1] += 1
		if range_max <= 2 * k - 1:
			pref[range_max] -= 1
	for i in range(1, len(pref)):
		pref[i] += pref[i - 1]
	for i in range(2 * k):
		c.append(n - pref[i] - li[i])
	print(min(c))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	ans = [0] * (2 * k + 2)
	aa = []
	for i in range(n // 2):
		mm = min(lis[i], lis[n - i - 1])
		mx = max(lis[i], lis[n - i - 1])
		aa.append([mm, mx])
		ans[mm + 1] += 1
		ans[mx + k + 1] -= 1
	for i in range(1, 2 * k + 2):
		ans[i] += ans[i - 1]
	for i in range(2, 2 * k + 2):
		ans[i] += n - ans[i] * 2
	for i in range(n // 2):
		ans[aa[i][0] + aa[i][1]] -= 1
	print(min(ans[2:]))


from sys import *
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0] * (2 * k + 1)
	c = [0] * (2 * k + 1)
	mn = 1e+18
	for i in range(n // 2):
		(x, y) = (a[i], a[n - i - 1])
		(x, y) = (min(x, y), max(x, y))
		sn = x + y
		if sn + 1 <= 2 * k:
			b[sn + 1] += 1
		if sn - 1 >= 0:
			c[sn - 1] += 1
		if sn - y >= 0:
			c[sn - y] += 1
		if sn + (k - x) + 1 <= 2 * k:
			b[sn + (k - x) + 1] += 1
	for i in range(1, 2 * k + 1):
		b[i] += b[i - 1]
	for i in range(2 * k - 1, -1, -1):
		c[i] += c[i + 1]
	for i in range(2 * k + 1):
		mn = min(mn, b[i] + c[i])
	stdout.write(str(mn) + '\n')


t = int(input())
for i1 in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	sums = [0] * (2 * k + 2)
	arr = [0] * (2 * k + 2)
	pref = [0] * (2 * k + 2)
	for i2 in range(0, n // 2):
		temp = a[i2] + a[n - i2 - 1]
		sums[temp] += 1
		arr[min(a[i2], a[n - i2 - 1]) + 1] += 1
		arr[max(a[i2], a[n - i2 - 1]) + k + 1] -= 1
	temp = 0
	for i2 in range(len(arr)):
		temp += arr[i2]
		pref[i2] = temp
	result = 90000000000.0
	for i2 in range(len(arr)):
		temp = pref[i2] - sums[i2] + 2 * (n // 2 - pref[i2])
		result = min(temp, result)
	print(result)


for test in range(int(input())):
	(n, k) = map(int, input().split())
	a = [*map(int, input().split())]
	breakdown = [(a[i], a[n - 1 - i]) for i in range(n // 2) if not (a[i] > k and a[n - 1 - i] > k)]
	update = n - 2 * len(breakdown)
	score = [0 for value in range(2 * k + 2)]
	for pair in breakdown:
		(a, b) = pair
		if a <= k and b <= k:
			score[2] += 2
			score[min(a, b) + 1] -= 1
			score[max(a, b) + k + 1] += 1
			score[a + b] -= 1
			score[a + b + 1] += 1
		elif a >= k:
			score[2] += 2
			score[b + 1] -= 1
			score[b + k + 1] += 1
		elif b >= k:
			score[2] += 2
			score[a + 1] -= 1
			score[a + k + 1] += 1
	control = 0
	minimum = n
	for key in score[2:2 * k + 1]:
		control += key
		minimum = min(minimum, control)
	print(update + minimum)


from collections import Counter
t = int(input())
for T in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	pair = []
	for i in range(n // 2):
		pair.append(a[i] + a[n - i - 1])
	f = Counter(pair)
	event = []
	for i in range(n // 2):
		event.append([min(a[i], a[n - i - 1]) + 1, -1])
		event.append([max(a[i], a[n - i - 1]) + k + 1, +1])
	event.sort()
	it = 0
	ans = n + 100
	offset = n
	for x in range(1, 2 * k + 1):
		while it < n and event[it][0] <= x:
			offset += event[it][1]
			it += 1
		ans = min(ans, offset - f[x])
	print(ans)


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	hashtable = defaultdict(int)
	prefix = [0] * (2 * k + 2)
	for i in range(n // 2):
		hashtable[l[i] + l[n - i - 1]] += 1
		prefix[min(l[i], l[n - i - 1]) + 1] += 1
		prefix[max(l[i], l[n - i - 1]) + k + 1] -= 1
	presum = 0
	for i in range(2 * k + 1):
		presum += prefix[i]
		prefix[i] = presum
	minreplace = 10 ** 6
	for i in range(2, 2 * k + 1):
		ch0 = hashtable[i]
		ch1 = prefix[i] - ch0
		ch2 = (n // 2 - ch1 - ch0) * 2
		minreplace = min(minreplace, ch1 + ch2)
	print(minreplace)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	su = [0] * (2 * k + 2)
	for i in range(n // 2):
		(a, b) = (min(ar[i], ar[n - i - 1]), max(ar[i], ar[n - i - 1]))
		su[0] += 2
		su[a + 1] -= 1
		su[a + b] -= 1
		su[a + b + 1] += 1
		su[b + k + 1] += 1
	ans = []
	prev = 0
	for j in range(2 * k + 1):
		prev += su[j]
		ans.append(prev)
	print(min(ans))


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	n = inp()
	a = inpl()
	b = a[:]
	b.sort()
	res = []
	for i in range(n - 2):
		now = b[i]
		for j in range(i, n):
			if a[j] == now:
				break
		while j - i > 1:
			res.append(j - 2 + 1)
			(a[j - 2], a[j - 1], a[j]) = (a[j], a[j - 2], a[j - 1])
			j -= 2
		if j - i == 1:
			res.append(i + 1)
			res.append(i + 1)
			(a[i], a[i + 1], a[i + 2]) = (a[i + 1], a[i + 2], a[i])
	if a[n - 2] > a[n - 1]:
		if len(set(a)) == n:
			print(-1)
			continue
		same = -1
		for i in range(n - 1):
			if a[i] == a[i + 1]:
				same = i
		if same == -1:
			for i in range(n - 2):
				if a[i] == a[-1]:
					same = i
		for i in range(same, n - 2)[::-1]:
			res.append(i + 1)
	print(len(res))
	print(*res)


def run(lst, n, k):
	pref = [0 for i in range(2 * k + 2)]
	for i in range(int(n / 2)):
		l = lst[i]
		r = lst[n - i - 1]
		menor = min(l, r)
		maior = max(l, r)
		pref[1] += 2
		pref[menor + 1] -= 1
		pref[l + r] -= 1
		pref[l + r + 1] += 1
		pref[maior + k + 1] += 1
	for i in range(1, len(pref)):
		pref[i] += pref[i - 1]
	print(min(pref[2:-1]))
i = int(input())
for _ in range(i):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	run(lst, n, k)


t = int(input())
for x in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	pair_sum = [0 for y in range(2 * k + 2)]
	i = 0
	while i < n // 2:
		pair_sum[2] += 2
		pair_sum[min(a[i], a[n - i - 1]) + 1] += -1
		pair_sum[max(a[i], a[n - i - 1]) + k + 1] += 1
		pair_sum[a[i] + a[n - i - 1]] += -1
		pair_sum[a[i] + a[n - i - 1] + 1] += 1
		i += 1
	min_val = pair_sum[2]
	for i in range(3, 2 * k + 1):
		pair_sum[i] += pair_sum[i - 1]
		if pair_sum[i] < min_val:
			min_val = pair_sum[i]
	print(min_val)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	dic1 = {}
	li = [0] * (2 * k + 2)
	ar = list(map(int, input().split()))
	for i in range(n // 2):
		x = ar[i]
		y = ar[-(i + 1)]
		big = max(x, y)
		sma = min(x, y)
		x = x + y
		if x in dic1:
			dic1[x] += 1
		else:
			dic1[x] = 1
		li[sma + 1] += 1
		li[big + k + 1] -= 1
	for i in range(1, 2 * k + 2):
		li[i] += li[i - 1]
	br = []
	for j in range(1, 2 * k + 2):
		br.append(li[j] - dic1.get(j, 0) + (n // 2 - li[j]) * 2)
	print(min(br))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	pre = [0 for i in range(2 * k + 2)]
	arr = list(map(int, input().split()))
	zero = {}
	cnt1 = cnt2 = cnt0 = cnt = 0
	mini = float('inf')
	for i in range(n // 2):
		try:
			zero[arr[i] + arr[n - i - 1]] += 1
		except:
			zero[arr[i] + arr[n - i - 1]] = 1
		l = arr[i]
		r = arr[n - i - 1]
		(l, r) = sorted([l, r])
		pre[l + 1] += 1
		pre[r + k + 1] -= 1
	for i in range(1, len(pre)):
		pre[i] += pre[i - 1]
	for i in range(2, 2 * k + 1):
		cnt0 = zero.get(i, 0)
		cnt1 = pre[i] - cnt0
		cnt2 = n // 2 - cnt1 - cnt0
		cnt = 2 * cnt2 + cnt1
		mini = min(cnt, mini)
	print(mini)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	t = inp()
	for i in range(t):
		solve()

def solve():
	nk = inlt()
	n = nk[0]
	k = nk[1]
	lst = inlt()
	count_map = {}
	prefs = [0] * (2 * k + 2)
	for i in range(n // 2):
		a = lst[i]
		b = lst[n - i - 1]
		s = a + b
		count_map[s] = count_map.get(s, 0) + 1
		start = min(a, b) + 1
		end = max(a, b) + k + 1
		prefs[start] += 1
		prefs[end] -= 1
	sums = []
	total = 0
	for num in prefs:
		total += num
		sums.append(total)
	min_len = n
	for x in range(2, 2 * k + 1):
		cur = sums[x] - count_map.get(x, 0) + (n // 2 - sums[x]) * 2
		min_len = min(min_len, cur)
	print(min_len)
BUFSIZE = 8192

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

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

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	stats = {}
	for i in range(n // 2):
		(a1, an) = (a[i], a[n - i - 1])
		x = a1 + an
		stats[x - max(a1, an) + 1] = stats.get(x - max(a1, an) + 1, 0) - 1
		stats[x] = stats.get(x, 0) - 1
		stats[x + 1] = stats.get(x + 1, 0) + 1
		stats[x + (k - min(a1, an)) + 1] = stats.get(x + (k - min(a1, an)) + 1, 0) + 1
	min_sum = n
	cur_sum = n
	for (k, diff) in sorted(stats.items(), key=lambda xx: xx[0]):
		cur_sum += diff
		if cur_sum < min_sum:
			min_sum = cur_sum
	print(min_sum)


inf = float('inf')
T = int(input())
for i in range(T):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	B = [0] * (2 * K + 1)
	C = [0] * (2 * K + 2)
	for i in range(N // 2):
		(a, b) = (A[i], A[N - i - 1])
		if a > b:
			(a, b) = (b, a)
		B[a + b] += 1
		C[a + 1] += 1
		C[K + b + 1] -= 1
	ans = inf
	M = 0
	for k in range(1, 2 * K + 1):
		C[k] += C[k - 1]
		(b, c) = (B[k], C[k])
		a = c - b + 2 * (N // 2 - c)
		ans = min(ans, a)
	print(ans)


def change(i, j, k):
	global a
	(a[i], a[j], a[k]) = (a[k], a[i], a[j])
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	arr = a[:]
	b = sorted(a)
	if a == b:
		print(0)
		print()
		continue
	i = 0
	ans = []
	flag = 0
	while i < n:
		if a[i] == b[i]:
			i += 1
			continue
		ind = a[i:].index(b[i]) + i
		while a[i] != b[i]:
			if ind == i + 1:
				if ind + 1 >= len(a):
					flag = 1
					break
				ans.append((i, ind, ind + 1))
				change(i, ind, ind + 1)
				ans.append((i, ind, ind + 1))
				change(i, ind, ind + 1)
				break
			else:
				ans.append((ind - 2, ind - 1, ind))
				change(ind - 2, ind - 1, ind)
				ind -= 2
		if flag:
			break
		i += 1
	if flag:
		if len(set(a)) == n:
			print(-1)
			continue
		elif a[-3] == a[-1]:
			ans.append((n - 3, n - 2, n - 1))
		else:
			ans = []
			a = arr[:]
			flag2 = 0
			temp = sorted(a, reverse=True)
			for i in range(1, n):
				if temp[i] == temp[i - 1]:
					number = temp[i]
					break
			i = 0
			while i < n:
				if a[i] == b[i] and (i == 0 or a[i] != a[i - 1] or flag2):
					i += 1
					continue
				elif i != 0 and a[i] == a[i - 1]:
					if not flag2 and a[i] == number:
						ans.append((i - 1, i, i + 1))
						change(i - 1, i, i + 1)
						ans.append((i - 1, i, i + 1))
						change(i - 1, i, i + 1)
						ans.append((i, i + 1, i + 1))
						change(i, i + 1, i + 2)
						ans.append((i, i + 1, i + 2))
						change(i, i + 1, i + 2)
						flag2 = 1
					i += 1
					continue
				ind = a[i:].index(b[i]) + i
				while a[i] != b[i]:
					if ind == i + 1:
						ans.append((i, ind, ind + 1))
						change(i, ind, ind + 1)
						ans.append((i, ind, ind + 1))
						change(i, ind, ind + 1)
						break
					else:
						ans.append((ind - 2, ind - 1, ind))
						change(ind - 2, ind - 1, ind)
						ind -= 2
				if i != 0 and a[i] == a[i - 1] and (flag2 == 0) and (a[i] == number):
					ans.append((i - 1, i, i + 1))
					change(i - 1, i, i + 1)
					ans.append((i - 1, i, i + 1))
					change(i - 1, i, i + 1)
					ans.append((i, i + 1, i + 1))
					change(i, i + 1, i + 2)
					ans.append((i, i + 1, i + 2))
					change(i, i + 1, i + 2)
					flag2 = 1
				i += 1
	print(len(ans))
	for i in ans:
		print(i[0] + 1, end=' ')
	print()


def RA():
	l = input().split()
	return [int(s) for s in l]

def solve():
	(n, k) = RA()
	arr = RA()
	scores = [[0, 0, 0] for i in range(2 * k + 1)]
	for i in range(n // 2):
		a = arr[i]
		b = arr[n - i - 1]
		mini = min(a, b) + 1
		maxi = a + b + k - min(a, b)
		scores[mini][0] += 1
		scores[a + b][1] += 1
		scores[maxi][2] += 1
	needChange = n
	best = needChange
	for i in range(2, 2 * k + 1):
		needChange -= scores[i][0]
		best = min(best, needChange - scores[i][1])
		needChange += scores[i][2]
	print(best)
t = int(input())
for i in range(t):
	solve()


def answer():
	s = [0] * (2 * k + 1)
	ele_l = [0] * (2 * k + 1)
	sub = [0] * (2 * k + 2)
	for i in range(n // 2):
		s[a[i] + a[n - i - 1]] += 1
		ele_l[min(a[i], a[n - i - 1]) + 1] += 1
		sub[max(a[i], a[n - i - 1]) + k + 1] -= 1
	ans = 1000000000.0
	e_less = 0
	for i in range(2 * k + 1):
		e_less += ele_l[i] + sub[i]
		opp = n - e_less - s[i]
		ans = min(ans, opp)
	return ans
for T in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	print(answer())


import sys
input = sys.stdin.readline
from collections import defaultdict as dd, deque as dq
t = int(input())
import bisect
while t:
	d = dd(int)
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ll = []
	mx = 1000000000000000
	mi = -1
	ll = []
	l2 = []
	ri = -1
	le = mx
	for i in range(n // 2):
		d[l[i] + l[n - i - 1]] += 1
		mx = min(mx, max(l[i], l[n - i - 1]))
		mi = max(mi, min(l[i], l[n - i - 1]))
		ll.append(max(l[i], l[n - i - 1]) + k)
		l2.append(min(l[i], l[n - i - 1]) + 1)
		le = min(le, l[i] + l[n - i - 1])
		ri = max(ri, l[i] + l[n - i - 1])
	res = n // 2
	ll.sort()
	l2.sort()
	ri = ll[-1]
	if le > ri:
		(le, ri) = (ri, le)
	mx = 0
	ind = 100000000000
	for i in range(le, ri + 1):
		cou = bisect.bisect_left(ll, i)
		cou2 = n // 2 - bisect.bisect_right(l2, i)
		if mx < d[i] - cou - cou2:
			mx = d[i] - cou - cou2
	cou = 0
	print(res - mx)
	t -= 1


t = 1
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = [(a[i], i) for i in range(n)]
	a.sort()
	rev = 0
	for i in range(n):
		(val, id) = a[i]
		for j in range(i):
			(sval, sid) = a[j]
			if sid > id:
				rev += 1
	if rev % 2 == 1:
		for i in range(1, n):
			if a[i][0] == a[i - 1][0]:
				(a[i - 1], a[i]) = (a[i], a[i - 1])
				break
		else:
			print(-1)
			continue
	A = [-1] * n
	for i in range(n):
		(val, id) = a[i]
		A[id] = i + 1
	a = [0] + A
	ID = [-1] * (n + 1)
	for i in range(1, n + 1):
		ID[a[i]] = i
	goal = 1
	res = []

	def swap(i):
		res.append(i)
		(ID[a[i]], ID[a[i + 1]], ID[a[i + 2]]) = (i + 1, i + 2, i)
		(a[i], a[i + 1], a[i + 2]) = (a[i + 2], a[i], a[i + 1])
	while n >= goal:
		start = ID[goal]
		if (start - goal) % 2 == 1:
			if start == n:
				swap(start - 2)
				swap(start - 2)
				start = ID[goal]
			else:
				swap(start - 1)
				start = ID[goal]
		while start != goal:
			swap(start - 2)
			start = ID[goal]
		goal += 1
	print(len(res))
	print(*res)


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 10 ** 9 + 7

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k)))) % NUMBER
from collections import deque, defaultdict
import heapq
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def dfs(g, timeIn, timeOut, depths, parents):
	cnt = 0
	stack = [[1, 0, 0, 0]]
	while stack:
		(v, neig_i, parent, depth) = stack[-1]
		parents[v] = parent
		depths[v] = depth
		if neig_i == 0:
			timeIn[v] = cnt
			cnt += 1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i += 1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u, 0, v, depth + 1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1
cnt = 0

@bootstrap
def dfs(v, adj, timeIn, timeOut, depths, parents, parent=0, depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt += 1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u, adj, timeIn, timeOut, depths, parents, v, depth + 1)
	timeOut[v] = cnt
	cnt += 1
	yield

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

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

def get_num_2_5(n):
	twos = 0
	fives = 0
	while n > 0 and n % 2 == 0:
		n //= 2
		twos += 1
	while n > 0 and n % 5 == 0:
		n //= 5
		fives += 1
	return (twos, fives)

def shift(a, i, num):
	for _ in range(num):
		(a[i], a[i + 1], a[i + 2]) = (a[i + 2], a[i], a[i + 1])

def solution(a, n):
	inv = 0
	for i in range(n):
		for j in range(i):
			if a[j] > a[i]:
				inv += 1
	indexes = []
	shifted = True
	while shifted:
		shifted = False
		for i in range(n - 2):
			b = a[i:i + 3]
			if b == sorted(b):
				continue
			if len(set(b)) == 2:
				if b[0] == b[1]:
					shift(a, i, 1)
					shifted = True
					indexes.extend([i])
				elif b[0] == b[2]:
					if b[2] < b[1]:
						shift(a, i, 1)
						shifted = True
						indexes.extend([i])
					else:
						shift(a, i, 2)
						shifted = True
						indexes.extend([i, i])
				else:
					shift(a, i, 2)
					shifted = True
					indexes.extend([i, i])
			elif a[i] == max(b):
				shift(a, i, 2)
				shifted = True
				indexes.extend([i, i])
			elif a[i + 1] == max(b):
				shift(a, i, 1)
				shifted = True
				indexes.append(i)
	shifted = True
	while shifted:
		shifted = False
		for i in range(n - 2):
			b = a[i:i + 3]
			if b == sorted(b):
				continue
			if len(set(b)) == 2:
				if b[0] == b[1]:
					shift(a, i, 1)
					shifted = True
					indexes.extend([i])
				elif b[0] == b[2]:
					if b[2] < b[1]:
						shift(a, i, 1)
						shifted = True
						indexes.extend([i])
					else:
						shift(a, i, 2)
						shifted = True
						indexes.extend([i, i])
				else:
					shift(a, i, 2)
					shifted = True
					indexes.extend([i, i])
			elif a[i + 1] == min(b):
				shift(a, i, 2)
				shifted = True
				indexes.extend([i, i])
			elif a[i + 2] == min(b):
				shift(a, i, 1)
				shifted = True
				indexes.append(i)
	for i in range(len(indexes)):
		indexes[i] += 1
	if sorted(a) == a:
		return str(len(indexes)) + '\n' + ' '.join(map(str, indexes))
	return '-1'

def main():
	T = 1
	T = ri()
	for i in range(T):
		n = ri()
		a = ria()
		x = solution(a, n)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


import sys
input = sys.stdin.readline
ans = []
t = int(input())
from itertools import accumulate
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	ans = [0] * (2 * k + 2)
	for i in range(n // 2):
		sum_ = a[i] + a[-i - 1]
		max_ = max(a[i], a[-i - 1]) + k
		min_ = min(a[i], a[-i - 1]) + 1
		ans[0] += 2
		ans[min_] -= 1
		ans[max_ + 1] += 1
		ans[sum_] -= 1
		ans[sum_ + 1] += 1
	if n == 2:
		print(0)
		continue
	acm = list(accumulate(ans))
	print(min(acm))


t1 = int(input())
for x in range(t1):
	(n, k) = map(int, input().split())
	t = list(map(int, input().split()))
	el_sum = [0] * (2 * k + 2)
	for y in range(0, n // 2):
		l = t[y]
		r = t[n - y - 1]
		el_sum[0] += 2
		el_sum[l + r] -= 1
		el_sum[l + r + 1] += 1
		el_sum[min(l, r) + 1] -= 1
		el_sum[max(l, r) + k + 1] += 1
	for y in range(2 * k + 1):
		el_sum[y + 1] += el_sum[y]
	print(min(el_sum))


from sys import stdin, exit
input = stdin.readline

def i():
	return input()

def ii():
	return int(input())

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

def liis():
	return list(map(int, input().split()))

def print_array(a):
	print(' '.join(map(str, a)))
t = ii()
for _ in range(t):
	(n, k) = iis()
	a = liis()
	counter = {}
	poss = []
	for i in range(n // 2):
		ini = a[i]
		fim = a[n - i - 1]
		if ini <= k and fim <= k:
			if ini + fim not in counter:
				counter[ini + fim] = 0
			counter[ini + fim] += 1
	add = [0 for i in range(2 * k + 2)]
	rem = [0 for i in range(2 * k + 2)]
	alt = [0 for i in range(2 * k + 2)]
	for i in range(n // 2):
		ini = a[i]
		fim = a[n - i - 1]
		mini = 1 + min(ini, fim)
		maxi = k + max(ini, fim)
		alt[ini + fim] += 1
		add[mini] += 1
		rem[maxi + 1] += 1
	count = 0
	for i in range(2, len(add) - 1):
		count += add[i] - rem[i]
		two = (n // 2 - count) * 2
		poss.append(count - alt[i] + two)
	print(min(poss))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	c = [0] * (2 * k + 2)
	for i in range(n // 2):
		x = a[i]
		y = a[n - i - 1]
		maxi = max(x, y) + k
		mini = min(x, y) + 1
		c[x + y] -= 1
		c[x + y + 1] += 1
		c[mini] += 1
		c[maxi + 1] -= 1
		c[2] += 2
		c[mini] -= 2
		c[maxi + 1] += 2
		c[2 * k + 1] -= 2
	ans = []
	cur = 0
	for i in range(2, 2 * k + 1):
		cur += c[i]
		ans.append(cur)
	print(min(ans))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ones = [0] * (2 * k + 4)
	zeros = [0] * (2 * k + 4)
	for i in range(n // 2):
		x = l[i]
		y = l[n - i - 1]
		if x > y:
			(x, y) = (y, x)
		zeros[x + y] += 1
		ones[x + 1] += 1
		ones[y + k + 1] -= 1
	for i in range(1, 2 * k + 4):
		ones[i] += ones[i - 1]
	ans = 1000000
	for i in range(1, 2 * k + 4):
		res = ones[i] - zeros[i] + max(0, 2 * (n // 2 - ones[i]))
		ans = min(ans, res)
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		nums = list(map(int, input().split()))
		sumList = [0] * (2 * k + 1)
		checkList = [0] * (2 * k + 1)
		for i in range(n // 2):
			s = max(nums[i], nums[-i - 1]) + k
			t = min(nums[i], nums[-i - 1]) + 1
			checkList[2] += 2
			checkList[t] -= 1
			checkList[nums[i] + nums[-i - 1]] -= 1
			if nums[i] + nums[-i - 1] < 2 * k:
				checkList[nums[i] + nums[-i - 1] + 1] += 1
			if s < 2 * k:
				checkList[s + 1] += 1
		for i in range(2, 2 * k + 1):
			sumList[i] = sumList[i - 1] + checkList[i]
		ans = n
		for i in range(2, 2 * k + 1):
			ans = min(sumList[i], ans)
		print(ans)
	return
main()


def run(lst, n, k):
	ans = float('inf')
	cnt = [0 for i in range(int(2 * k + 1))]
	for i in range(int(n / 2)):
		soma = lst[i] + lst[n - i - 1]
		cnt[soma] += 1
	pref = [0 for i in range(int(2 * k + 2))]
	for i in range(int(n / 2)):
		menor = min(lst[i] + 1, lst[n - i - 1] + 1)
		maior = max(lst[i] + k, lst[n - i - 1] + k)
		pref[menor] += 1
		pref[maior + 1] -= 1
	for i in range(1, len(pref) - 1):
		pref[i] += pref[i - 1]
	for i in range(1, len(pref) - 1):
		pref[i] = n - cnt[i] - pref[i]
	print(min(pref[2:-1]))
i = int(input())
for _ in range(i):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	run(lst, n, k)


class IndexingList:
	from collections import defaultdict

	def __init__(self, lst):
		self.lst = lst
		self.indexes = self.defaultdict(set)
		for (i, e) in enumerate(self.lst):
			self.indexes[e].add(i)

	def __getitem__(self, k):
		assert isinstance(k, int)
		return self.lst[k]

	def __setitem__(self, k, v):
		assert isinstance(k, int)
		old_v = self.lst[k]
		self.indexes[old_v].remove(k)
		self.indexes[v].add(k)
		self.lst[k] = v

	def __len__(self):
		return len(self.lst)

	def index(self, k):
		s = self.indexes[k]
		if len(s) == 0:
			assert False
		return next(iter(s))

	def __repr__(self):
		return self.lst.__repr__()

	def __eq__(self, other):
		if isinstance(other, IndexingList):
			return self.lst == other.lst
		elif isinstance(other, list):
			return self.lst == other
		assert False
num_calls = 0

def swaps(A):
	global num_calls
	A = IndexingList(A)
	ret = []
	for k in range(len(A) - 1, 1, -1):
		assert A.index(k) <= k
		while A.index(k) < k:
			num_calls += 1
			s = max(A.index(k) - 1, 0)
			ret += [s]
			(A[s], A[s + 1], A[s + 2]) = (A[s + 2], A[s], A[s + 1])
	if sorted(A) != A:
		return None
	return [x + 1 for x in ret]

def ans(A):
	seen = set()
	duplicate = None
	for a in A:
		if a in seen:
			duplicate = a
			break
		else:
			seen.add(a)
	A = [(e, i) for (i, e) in enumerate(A)]
	A = sorted(A)
	A = [(i, j, e) for (j, (e, i)) in enumerate(A)]
	A = sorted(A)
	A2 = None
	if duplicate is not None:
		duplicate_indices = set()
		for (i, (_, _, e)) in enumerate(A):
			if e == duplicate:
				duplicate_indices.add(i)
		assert len(duplicate_indices) >= 2
		(p, q) = list(duplicate_indices)[0:2]
		A2 = A[:]
		(A2[p], A2[q]) = (A2[q], A2[p])
		A2 = [j for (i, j, e) in A2]
	A = [j for (i, j, e) in A]
	s = swaps(A)
	s2 = None
	if A2 is not None:
		s2 = swaps(A2)
	if s is not None:
		print(len(s))
		print(*s)
	elif s2 is not None:
		print(len(s2))
		print(*s2)
	else:
		print(-1)
T = int(input())
for _ in range(T):
	input()
	A = input().split(' ')
	A = list(map(int, A))
	ans(A)


from sys import stdin
import sys
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	count = [0] * (2 * k + 1)
	for i in range(n // 2):
		count[arr[i] + arr[n - 1 - i]] += 1
	prev = [0] * (2 * k + 2)
	for i in range(n // 2):
		left = min(arr[i], arr[n - 1 - i]) + 1
		right = max(arr[i], arr[n - i - 1]) + k
		prev[left] += 1
		prev[right + 1] -= 1
	for i in range(1, 2 * k + 2):
		prev[i] += prev[i - 1]
	ans = 1000000
	for i in range(2, 2 * k + 1):
		ans = min(ans, prev[i] - count[i] + (n // 2 - prev[i]) * 2)
	print(ans)


from random import randint
it = lambda : list(map(int, input().strip().split()))

def solve():
	N = int(input())
	A = it()
	inversion = 0
	duplicate = None
	for i in range(N):
		for j in range(i):
			if A[j] > A[i]:
				inversion += 1
			elif A[j] == A[i]:
				duplicate = A[j]
	if inversion % 2:
		if duplicate is None:
			print(-1)
			return
		l = 2
		for i in range(N - 1, -1, -1):
			if A[i] == duplicate:
				l -= 1
				if l == 0:
					A[i] += 0.1
					break
	A = [[a, i] for (i, a) in enumerate(A)]
	B = sorted(A)
	I = []
	for i in range(N):
		if A[i] == B[i]:
			continue
		for idx in range(i + 1, N):
			if A[idx] == B[i]:
				break
		while idx > i:
			if idx >= i + 2:
				idx -= 2
				I.append(idx + 1)
				(A[idx], A[idx + 1], A[idx + 2]) = (A[idx + 2], A[idx], A[idx + 1])
			else:
				idx -= 1
				I.extend([idx + 1] * 2)
				(A[idx], A[idx + 1], A[idx + 2]) = (A[idx + 1], A[idx + 2], A[idx])
	print(len(I))
	print(' '.join(map(str, I)))
T = int(input())
for _ in range(T):
	solve()


import sys
input = sys.stdin.readline
from collections import deque
t = int(input())

def inc(n, arr, l, r):
	if l <= r and l >= 0:
		arr[l] += n
		if r + 1 <= len(arr) - 1:
			arr[r + 1] -= n
for i1 in range(t):
	(n, k) = list(map(int, input().split(' ')))
	l1 = list(map(int, input().split(' ')))
	arr = [0] * (2 * k + 1)
	for i in range(n // 2):
		z1 = l1[i]
		z2 = l1[n - i - 1]
		s = z1 + z2
		min1 = min(z1, z2)
		max1 = max(z1, z2)
		if s != 2 * k:
			(l, r) = (s + k - min1 + 1, 2 * k)
			inc(2, arr, l, r)
			(l, r) = (s + 1, s + k - min1)
			inc(1, arr, l, r)
		(l, r) = (s - (max1 - 1), s - 1)
		inc(1, arr, l, r)
		(l, r) = (0, s - (max1 - 1) - 1)
		inc(2, arr, l, r)
	for i in range(1, len(arr)):
		arr[i] += arr[i - 1]
	print(min(arr))


import sys
lines = sys.stdin.readlines()
T = int(lines[0].strip())
for t in range(T):
	(n, k) = map(int, lines[2 * t + 1].strip().split(' '))
	nums = list(map(int, lines[2 * t + 2].strip().split(' ')))
	noChange = {}
	oneChange = {}
	for i in range(2, 2 * k + 4):
		noChange[i] = 0
		oneChange[i] = 0
	for i in range(n // 2):
		l = nums[i]
		r = nums[-i - 1]
		noChange[l + r] += 1
		oneChange[min(l, r) + 1] += 1
		oneChange[l + r] -= 1
		oneChange[l + r + 1] += 1
		oneChange[max(l, r) + k + 1] -= 1
	for i in range(3, 2 * k + 4):
		oneChange[i] += oneChange[i - 1]
	res = n
	for i in range(2, 2 * k + 3):
		tmp = n - oneChange[i] - 2 * noChange[i]
		res = min(tmp, res)
	print(res)


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	count = [0 for i in range(2 * k + 1)]
	pref = [0 for i in range(2 * k + 2)]
	for i in range(len(arr) // 2):
		summ = arr[i] + arr[-(i + 1)]
		count[summ] += 1
		minval = 1 + min(arr[i], arr[-(i + 1)])
		maxval = k + max(arr[i], arr[-(i + 1)])
		pref[minval] += 1
		pref[maxval + 1] -= 1
	for i in range(1, len(pref)):
		pref[i] += pref[i - 1]
	ans = n
	for i in range(2, 2 * k + 1):
		changes = pref[i] - count[i] + (n // 2 - pref[i]) * 2
		ans = min(ans, changes)
	print(ans)


t = int(input())
for _t in range(t):
	(n, k) = map(int, input().strip().split())
	a = [int(x) for x in input().split()]
	(ref, intvls) = (dict(), [])
	for i in range(n // 2):
		x = a[i] + a[n - i - 1]
		ref[x] = ref.get(x, 0) + 1
		intvls += [(min(a[i], a[n - i - 1]) + 1, max(a[i], a[n - i - 1]) + k)]
	ff = [0] * 2 * (k + 1)
	for (i, j) in intvls:
		ff[i] += 1
		ff[j + 1] += -1
	ans = 10 ** 9
	for i in range(2, 2 * k + 1):
		ff[i] += ff[i - 1]
		(no_of_0s, no_of_1s) = (ref.get(i, 0), ff[i] - ref.get(i, 0))
		no_of_2s = n // 2 - no_of_1s - no_of_0s
		ans = min(ans, no_of_2s * 2 + no_of_1s * 1 + no_of_0s * 0)
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	sums = dict()
	for i in range(len(arr) // 2):
		if arr[i] + arr[n - 1 - i] not in sums:
			sums[arr[i] + arr[n - 1 - i]] = 0
		sums[arr[i] + arr[n - 1 - i]] += 1
	mins = []
	maxs = []
	for i in range(len(arr) // 2):
		mins.append(arr[i] + arr[n - 1 - i] - max(arr[i], arr[n - 1 - i]) + 1)
		maxs.append(arr[i] + arr[n - 1 - i] - min(arr[i], arr[n - 1 - i]) + k)
	mins.sort()
	maxs.sort()
	minarr = []
	maxarr = []
	current = 0
	for i in range(2 * k + 1):
		while current < len(mins) and i == mins[current]:
			current += 1
		minarr.append(n // 2 - current)
	current = 0
	for i in range(2 * k + 1):
		while current < len(maxs) and i > maxs[current]:
			current += 1
		maxarr.append(current)
	ans = sys.maxsize
	for total in range(2, 2 * k + 1):
		if total in sums:
			temp = n // 2 + minarr[total] + maxarr[total] - sums[total]
		else:
			temp = n // 2 + minarr[total] + maxarr[total]
		if temp < ans:
			ans = temp
	print(ans)


def bs(a):
	low = 0
	high = len(li) - 1
	while low <= high:
		if high - low < 5:
			for i in range(low, high + 1):
				if li[i] >= a:
					return i
			return 0
		mid = (low + high) // 2
		if li[mid] >= a:
			high = mid
		else:
			low = mid + 1

def bs2(a):
	low = 0
	high = len(l) - 1
	while low <= high:
		if high - low < 5:
			for i in range(low, high + 1):
				if l[i] > a:
					return len(l) - i
			return 0
		mid = (low + high) // 2
		if l[mid] > a:
			high = mid
		else:
			low = mid + 1
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	s = list(map(int, input().split()))
	l = []
	li = []
	sum = []
	dict = {}
	for i in range(n // 2):
		l.append(min(s[i], s[n - 1 - i]))
		li.append(max(s[i], s[n - 1 - i]))
		if dict.get(s[i] + s[n - 1 - i]) is None:
			dict[s[i] + s[n - 1 - i]] = 0
		dict[s[i] + s[n - 1 - i]] += 1
	for x in dict.keys():
		sum.append((x, dict[x]))
	l.sort()
	li.sort()
	ans = n // 2
	for p in sum:
		x = 0
		y = 0
		if p[0] > k:
			x = p[0] - k
			y = k
			z = bs(x)
			ans = min(ans, 2 * z + n // 2 - z - p[1])
		else:
			x = 1
			y = p[0] - 1
			z = bs2(y)
			ans = min(ans, 2 * z + n // 2 - z - p[1])
	print(ans)


def main():
	t = int(input())
	while t > 0:
		(n, k) = map(int, input().split())
		arr = [int(e) for e in input().split()]
		mp = {}
		vec = []
		for i in range(int(n / 2)):
			if arr[i] + arr[n - i - 1] not in mp:
				mp[arr[i] + arr[n - i - 1]] = 0
			mp[arr[i] + arr[n - 1 - i]] += 1
			vec.append([min(arr[i], arr[n - i - 1]), max(arr[i], arr[n - i - 1])])
		pre = [0 for i in range(2 * k + 10)]
		for (f, s) in vec:
			l = f + 1
			r = s + k
			pre[l] += 1
			pre[r + 1] -= 1
		sum = 0
		for i in range(0, 2 * k + 10):
			sum += pre[i]
			pre[i] = sum
		ans = n
		for x in range(2, 2 * k + 1):
			cnt0 = mp.get(x)
			if cnt0 == None:
				cnt0 = 0
			cnt1 = pre[x] - cnt0
			cnt2 = n / 2 - cnt0 - cnt1
			ans = min(ans, cnt1 + 2 * cnt2)
		print(int(ans))
		t -= 1
main()


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
entries = inp()
for i in range(entries):
	l = inlt()
	n = l[0]
	k = l[1]
	lp = 2
	rp = 2 * k
	normal_sum = []
	l = inlt()
	list_val = [0] * (2 * k + 2)
	count = [0] * (2 * k + 2)
	for i in range(n // 2):
		val = l[i] + l[-i - 1]
		rp = k + max(l[i], l[-i - 1])
		lp = 1 + min(l[i], l[-i - 1])
		list_val[val] += 1
		count[lp] -= 1
		count[rp + 1] += 1
	curr = n
	ans = n
	for x in range(2, 2 * k + 2):
		curr += count[x]
		ans = min(ans, curr - list_val[x])
	print(ans)


t = int(input())
from collections import defaultdict
import math
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	seq = list(map(int, input().split()))
	prefix_arr = [0] * (2 * k + 10)
	zero_count = defaultdict(int)
	for i in range(n // 2):
		zero_count[seq[i] + seq[n - i - 1]] += 1
		(a, b) = sorted((seq[i], seq[n - i - 1]))
		L = a + 1
		R = b + k
		prefix_arr[L] += 1
		prefix_arr[R + 1] -= 1
	prefsum = 0
	for i in range(2 * k + 10):
		prefsum += prefix_arr[i]
		prefix_arr[i] = prefsum
	ans = n
	for i in range(2, 2 * k + 1):
		zero = zero_count[i]
		ones = prefix_arr[i] - zero
		twos = n // 2 - ones - zero
		total = ones + twos * 2
		ans = min(ans, total)
	print(ans)


def binsearch(a, x):
	left = 0
	right = len(a)
	while right > left + 1:
		mid = (left + right) // 2
		if a[mid][0] > x:
			right = mid
		else:
			left = mid
	return left
t = int(input())
for _ in range(t):
	(n, k) = tuple(map(int, input().split()))
	a = list(map(int, input().split()))
	count = {}
	ranges = {}
	for i in range(n // 2):
		s = a[i] + a[n - i - 1]
		if s in count:
			count[s] += 1
		else:
			count[s] = 1
		left = min(a[i], a[n - i - 1]) + 1
		right = max(a[i], a[n - i - 1]) + k + 1
		if left in ranges:
			ranges[left] += 1
		else:
			ranges[left] = 1
		if right in ranges:
			ranges[right] -= 1
		else:
			ranges[right] = -1
	runningsum = 0
	partials = []
	for key in sorted(ranges.keys()):
		runningsum += ranges[key]
		partials.append((key, runningsum))
	assert runningsum == 0
	res = n // 2
	for (k, v) in count.items():
		idx = binsearch(partials, k)
		res = min(res, n - partials[idx][1] - v)
	print(res)


t = int(input())
while t:
	(n, k) = map(int, input().rstrip().split())
	a = list(map(int, input().rstrip().split()))
	p = [0 for i in range(2 * k + 2)]
	f = p.copy()
	for i in range(n // 2):
		f[a[i] + a[n - i - 1]] += 1
		p[min(a[i], a[n - i - 1]) + 1] += 1
		p[max(a[i], a[n - i - 1]) + k + 1] -= 1
	s = 0
	for i in range(len(p)):
		s += p[i]
		p[i] = s
	ans = float('inf')
	for i in range(2, 2 * k + 1):
		ans = min(ans, p[i] - f[i] + (n // 2 - p[i]) * 2)
	print(ans)
	t -= 1


from itertools import accumulate
tests = int(input())
for t in range(tests):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	p = [(a[i], a[n - i - 1]) for i in range(n // 2)]
	r = [(min(a, b) + 1, +1) for (a, b) in p] + [(a + b, +1) for (a, b) in p] + [(a + b + 1, -1) for (a, b) in p] + [(max(a, b) + k + 1, -1) for (a, b) in p]
	print(n - max(list(accumulate([x for (_, x) in sorted(r)]))))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dp = [0] * (2 * k + 2)
	i = 0
	j = n - 1
	while i < j:
		(x, y) = (min(a[i], a[j]), max(a[i], a[j]))
		dp[0] += 2
		dp[x + 1] -= 1
		dp[x + y] -= 1
		dp[x + y + 1] += 1
		dp[y + k + 1] += 1
		i += 1
		j -= 1
	for i in range(1, len(dp)):
		dp[i] += dp[i - 1]
	print(min(dp))


def task(n, k, a):
	sums = {}
	maxk = k * 2 + 2
	mins = [0] * maxk
	maxs = [0] * maxk
	half = int(n / 2)
	for i in range(0, half):
		c = a[i]
		d = a[n - 1 - i]
		suma = c + d
		if not suma in sums:
			sums[suma] = 0
		sums[suma] += 1
		mins[min(c, d) + 1] += 1
		maxs[max(c, d) + k + 1] += 1
	value = 0
	best = half
	for i in range(0, maxk):
		value += mins[i] - maxs[i]
		if i in sums:
			one_swap = value - sums[i]
			two_swaps = half - value
			swaps = one_swap + 2 * two_swaps
			best = min(best, swaps)
	print(best)
t = int(input())
for i in range(0, t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	task(n, k, a)


N = int(input())
for i in range(N):
	(n, k) = list(map(int, input().strip().split(' ')))
	a = list(map(int, input().strip().split(' ')))
	pairs = []
	prefixSum = [0] * (2 * k + 2)
	ht = {}
	for i in range(n // 2):
		mi = min(a[i], a[n - i - 1])
		ma = max(a[i], a[n - i - 1])
		l = mi + 1
		r = ma + k
		if mi + ma not in ht:
			ht[mi + ma] = 1
		else:
			ht[mi + ma] += 1
		prefixSum[l] += 1
		prefixSum[r + 1] -= 1
	sum = 0
	for i in range(len(prefixSum)):
		sum += prefixSum[i]
		prefixSum[i] = sum
	minCnt = n
	for i in range(2, 2 * k + 1):
		zero = ht.setdefault(i, 0)
		ones = prefixSum[i] - zero
		twos = n // 2 - ones - zero
		count = twos * 2 + ones
		minCnt = min(count, minCnt)
	print(minCnt)


def __starting_point():
	n = int(input())
	for i in range(n):
		h = list(map(int, input().rstrip().split()))
		N = h[0]
		K = h[1]
		h = list(map(int, input().rstrip().split()))
		t = [0] * (2 * K + 2)
		for i in range(N // 2):
			t[h[i] + h[N - i - 1]] -= 1
			t[h[i] + h[N - i - 1] + 1] += 1
			t[max(h[i], h[N - i - 1]) + K + 1] += 1
			t[min(h[i], h[N - i - 1]) + 1] -= 1
		v = N
		minv = N
		for i in range(2 * K + 2):
			v += t[i]
			if v < minv:
				minv = v
		print(minv)
__starting_point()


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().split()]

def st():
	return input()

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input()]

def li3():
	return [int(i) for i in input()]
for _ in range(val()):
	(n, k) = li()
	l = li()
	cnt = Counter()
	mins = []
	maxs = []
	sums = []
	arr = [0] * (2 * k + 5)
	for i in range(n // 2):
		cnt[l[i] + l[n - i - 1]] += 1
		(a, b) = (max(l[i], l[n - i - 1]), min(l[i], l[n - i - 1]))
		arr[b] += 1
		arr[a + k] -= 1
		maxs.append(a + k - b)
		mins.append(b + 1)
	mins.sort()
	maxs.sort()
	ans = n
	curr = arr[1]
	for i in range(2, 2 * k + 1, 1):
		onecost = curr - cnt[i]
		twocost = n // 2 - curr
		ans = min(ans, onecost + twocost * 2)
		curr += arr[i]
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	pre = [0] * (2 * k + 2)
	d = [0] * (2 * k + 2)
	for i in range(n // 2):
		pre[min(a[i], a[n - i - 1]) + 1] += -1
		pre[max(a[i], a[n - i - 1]) + k + 1] += 1
		d[a[i] + a[n - i - 1]] += 1
	for i in range(1, 2 * k + 1):
		pre[i] += pre[i - 1]
	ans = n
	for i in range(1, 2 * k + 1):
		ans = min(ans, n + pre[i] - d[i])
	print(ans)


def solve(arr, s, k):
	hs = s // 2
	bal = max(arr)
	unchanged1 = [0] * (bal + k + 2)
	unchanged2 = [0] * (bal + k + 2)
	for i in range(hs):
		smax = max(arr[i], arr[s - 1 - i]) + k
		smin = min(arr[i], arr[s - 1 - i]) + 1
		unchanged1[smin] += 1
		unchanged1[smax + 1] -= 1
		unchanged2[arr[i] + arr[s - 1 - i]] += 2
	for i in range(1, bal + k + 2):
		unchanged1[i] += unchanged1[i - 1]
	for i in range(1, bal + k + 1):
		if unchanged2[i] > 0:
			unchanged1[i] += unchanged2[i] // 2
	mans = 0
	for i in range(1, bal + k + 1):
		mans = max(mans, unchanged1[i], unchanged2[i])
	return s - mans
tc = int(input())
fun = solve
ans = ''
for ll in range(tc):
	(_, k) = map(int, input().split())
	li = [int(x) for x in input().split()]
	fun(li, _, k)
	ans += '{}\n'.format(fun(li, _, k))
print(ans)


for f in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	nh = n // 2
	su = [0] * (2 * k + 1)
	mi = [0] * nh
	ma = [0] * nh
	for i in range(nh):
		su[a[i] + a[-i - 1]] += 1
		mi[i] = min(a[i], a[-i - 1]) + 1
		ma[i] = max(a[i], a[-i - 1]) + k
	mi.sort()
	ma.sort()
	mii = 0
	maa = 0
	sol = n
	for i in range(2 * k + 1):
		while mii < nh and mi[mii] <= i:
			mii += 1
		while maa < nh and ma[maa] < i:
			maa += 1
		sol = min(sol, n - su[i] - mii + maa)
	print(sol)


import math
import sys
from collections import defaultdict
from collections import Counter
from collections import deque
import bisect
from itertools import accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]
for _ in range(int(input())):
	(n, k) = ilele()
	A = alele()
	B = []
	mark = {}
	mins = [0] * (2 * k + 2)
	maxs = mins.copy()
	for i in range(n // 2):
		x = A[i]
		y = A[n - i - 1]
		mark[x + y] = mark.get(x + y, 0) + 1
		if x > y:
			(x, y) = (y, x)
		mins[x + 1] += 1
		maxs[y + k + 1] += 1
	v = 0
	Ans = n // 2
	for i in range(len(mins)):
		v += mins[i] - maxs[i]
		if i in mark:
			one = v - mark[i]
			two = n // 2 - v
			sw = one + 2 * two
			Ans = min(Ans, sw)
	print(Ans)


def swaps(A):
	ret = []
	for k in range(len(A) - 1, 1, -1):
		assert A.index(k) <= k
		while A.index(k) < k:
			s = max(A.index(k) - 1, 0)
			ret += [s]
			(A[s], A[s + 1], A[s + 2]) = (A[s + 2], A[s], A[s + 1])
	if sorted(A) != A:
		return None
	return [x + 1 for x in ret]

def ans(A):
	seen = set()
	duplicate = None
	for a in A:
		if a in seen:
			duplicate = a
			break
		else:
			seen.add(a)
	A = [(e, i) for (i, e) in enumerate(A)]
	A = sorted(A)
	A = [(i, j, e) for (j, (e, i)) in enumerate(A)]
	A = sorted(A)
	A2 = None
	if duplicate is not None:
		duplicate_indices = set()
		for (i, (_, _, e)) in enumerate(A):
			if e == duplicate:
				duplicate_indices.add(i)
		assert len(duplicate_indices) >= 2
		(p, q) = list(duplicate_indices)[0:2]
		A2 = A[:]
		(A2[p], A2[q]) = (A2[q], A2[p])
		A2 = [j for (i, j, e) in A2]
	A = [j for (i, j, e) in A]
	s = swaps(A)
	s2 = None
	if A2 is not None:
		s2 = swaps(A2)
	if s is not None:
		print(len(s))
		print(*s)
	elif s2 is not None:
		print(len(s2))
		print(*s2)
	else:
		print(-1)
T = int(input())
for _ in range(T):
	input()
	A = input().split(' ')
	A = list(map(int, A))
	ans(A)


import sys
import math
from collections import defaultdict

def lower(arr, num):
	if num > arr[-1]:
		return len(arr)
	(l, r) = (0, len(arr) - 1)
	ans = -1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] < num:
			l = mid + 1
			ans = mid
		else:
			r = mid - 1
	return ans

def lowera(arr, num):
	if num > arr[-1]:
		return len(arr) - 1
	(l, r) = (0, len(arr) - 1)
	ans = -1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] <= num:
			l = mid + 1
			ans = mid
		else:
			r = mid - 1
	return ans
t = int(sys.stdin.readline())
for _ in range(t):
	dic = defaultdict(int)
	(n, k) = map(int, sys.stdin.readline().split())
	arr = list(map(int, sys.stdin.readline().split()))
	small = []
	large = []
	(l, r) = (0, n - 1)
	while l <= r:
		dic[arr[l] + arr[r]] += 1
		small.append(min(arr[l], arr[r]))
		large.append(max(arr[l], arr[r]))
		l += 1
		r -= 1
	small.sort()
	large.sort()
	for i in range(len(small)):
		small[i] += 1
	for i in range(len(large)):
		large[i] += k
	small = [small[0] - 1] + small
	large = [large[0] - 1] + large
	ans = 10000000000.0
	for i in range(2, 2 * k + 1):
		a = lowera(small, i)
		b = lower(large, i)
		x = n // 2 - a
		if b < 1:
			y = 0
			b = 0
		s = x * 2 + a + y * 2 + b - dic[i]
		ans = min(ans, s)
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	sumFreq = []
	pref = []
	for i in range(2 * k + 2):
		pref.append(0)
		sumFreq.append(0)
	i = 0
	j = n - 1
	x = n // 2
	while x > 0:
		x -= 1
		s = a[i] + a[j]
		sumFreq[s] += 1
		p = k - min(a[i], a[j])
		q = max(a[i], a[j]) - 1
		r = [s - q, p + s]
		pref[r[0]] += 1
		pref[r[1] + 1] -= 1
		i += 1
		j -= 1
	for i in range(3, 2 * k + 1):
		pref[i] += pref[i - 1]
	ans = 1000000000.0
	for i in range(2, 2 * k + 1):
		ans = min(ans, pref[i] - sumFreq[i] + 2 * (n // 2 - pref[i]))
	print(ans)


import sys
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lim = 2 * k + 2
	l = list(map(int, input().split()))
	(cnt, val) = ([0] * lim, [0] * lim)
	for i in range(n // 2):
		(a, b) = (l[i], l[n - i - 1])
		cnt[a + b] += 1
		val[max(a + k, b + k) + 1] -= 1
		val[min(a + 1, b + 1)] += 1
	ans = 10 ** 12
	for i in range(1, 2 * k + 1):
		val[i] += val[i - 1]
	for s in range(2, lim):
		ans = min(ans, val[s] - cnt[s] + 2 * (n // 2 - val[s]))
	print(ans)


def solve(n, k, ls):
	ans = n
	sums = []
	constant = [0] * (2 * k + 1)
	for i in range(int(n / 2)):
		s = ls[i] + ls[n - i - 1]
		constant[s] += 1
	minmax = [0] * (2 * k + 1)
	for i in range(int(n / 2)):
		a = ls[i]
		b = ls[n - i - 1]
		min_sum = min(a, b) + 1
		max_sum = max(a, b) + k
		minmax[min_sum] += 1
		if max_sum == 2 * k:
			continue
		minmax[max_sum + 1] -= 1
	for i in range(1, 2 * k + 1):
		minmax[i] += minmax[i - 1]
	for x in range(2, 2 * k + 1):
		ans = min(ans, minmax[x] - constant[x] + (int(n / 2) - minmax[x]) * 2)
	return ans
no = int(input())
for i in range(no):
	(n, k) = tuple(map(int, input().strip().split()))
	ls = list(map(int, input().strip().split()))
	print(solve(n, k, ls))