#include <bits/stdc++.h>

#define int long long

using namespace std;

const int MAXN = 510;

int A[MAXN];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int T;
    cin >> T;

    while(T--)
    {
    	int N;
    	cin >> N;

    	for(int i = 1 ; i <= N ; i++)
    	{
    		cin >> A[i];
    	}

    	bool flag = true;

    	vector<int> res;

    	auto op = [&](int x)
    	{
    		res.push_back(x);
    		swap(A[x],A[x+1]);
    		flag = !flag;
    	};

    	for(int x = N ; x >= 5 ; x--)
    	{
    		int pos = -1;
    		for(int i = 1 ; i <= N ; i++)
    		{
    			if(A[i] == x)
    			{
    				pos = i;
    			}
    		}

    		if(pos == 1)
    		{
    			if(!flag)op(2);
    		}
    		if(pos == 2)
    		{
    			if(flag)op(3);
    		}
    		if(pos == 3)
    		{
    			if(!flag)op(4);
    		}
    		if(pos >= 4)
    		{
    			if(pos%2 == 1)
    			{
    				if(!flag)op(2);
    			}
    			else
    			{	
    				if(flag)op(1);
    			}
    		}

    		for(int i = pos ; i < x ; i++)
    		{
    			op(i);
    		}
    	}

    	if(N >= 4)
    	{
	    	int pos4 = -1;

	    	for(int i = 1 ; i <= 4 ; i++)
	    	{
	    		if(A[i] == 4)
	    		{
	    			pos4 = i;
	    		}
	    	}

	    	if(pos4 == 1)
	    	{
	    		if(!flag)op(2);
	    	}
	    	else if(pos4 == 2)
	    	{
	    		if(flag)op(3);
	    	}
	    	else if(pos4 == 3)
	    	{
	    		if(!flag)
	    		{
	    			op(2);
	    			op(3);
	    			pos4 = 2;
	    		}
	    	}
	    	else
	    	{

	    	}

	    	for(int i = pos4 ; i < 4 ; i++)
	    	{
	    		op(i);
	    	}
    	}

    	if(N >= 3)
    	{
	    	while(A[1] != 1 || A[2] != 2 || A[3] != 3)
	    	{
	    		if(flag)op(1);
	    		else op(2);
	    	}	
    	}
    	else
    	{
    		while(A[1] != 1 || A[2] != 2)
	    	{
	    		if(flag)op(1);
	    	}	
    	}


    	// for(int i = 1 ; i <= N ; i++)
    	// {
    	// 	cout << A[i] << " ";
    	// }
    	// cout << '\n';

    	cout << res.size() << '\n';

    	for(auto x : res)
    	{
    		cout << x << " ";
    	}
    	cout << '\n';
    }

    return 0;
}
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(b-1)),y(up?b:(a-1)){}_RX(int a):_RX(0,a){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef int64_t i64;
typedef uint64_t u64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

bool iseven(int x) {
	return (x & 1) == 0;
}

void oesort3(vector<int>& xs, int pos, bool even, vector<int>& ops) {

	int retry = 0;

	auto check = [&]() {
		for(auto i : range(3)) {
			if(xs[pos + i] != pos + i) {
				return false;
			}
		}
		return true;
	};

	while(!check()) {

		int p = (iseven(pos) == even) ? pos : pos + 1;
		ops.push_back(p);
		swap(xs[p], xs[p + 1]);
		even = !even;

		retry += 1;
		assert(retry < 100);
	}
}

void oesort(vector<int>& xs, int pos, bool even, vector<int>& ops) {

	const int N = xs.size();

	if(N - pos == 3) {
		return oesort3(xs, pos, even, ops);
	}

	assert(N - pos >= 4);

	int target = pos;
	while(xs[target] != pos) {
		target += 1;
	}

	if(target == pos) {
		oesort(xs, pos + 1, even, ops);
		return;
	}

	int retry = 0;

	while(iseven(target - 1) != even) {
		if(target - 2 >= pos) {
			ops.push_back(target - 2);
			swap(xs[target - 2], xs[target - 1]);
			even = !even;
		} else {
			ops.push_back(target);
			swap(xs[target], xs[target + 1]);
			target += 1;
			even = !even;
		}
		retry += 1;
		assert(retry < 100);
	}

	for(auto i : revrange(pos, target)) {
		assert(iseven(i) == even);
		ops.push_back(i);
		swap(xs[i], xs[i + 1]);
		even = !even;
	}

	oesort(xs, pos + 1, even, ops);
}

void solve() {

	const int N = read_item();
	vector<int> As(N);
	for(auto i : range(N)) {
		As[i] = (int)read_item() - 1;
	}

	if(N == 2) {
		if(As[0] == 0) {
			printf("0\n");
			return;
		} else {
			printf("1\n1\n");
			return;
		}
	}

	static vector<int> ops;
	ops.resize(0);

	oesort(As, 0, true, ops);
	int c = ops.size();

	assert(c <= N * N);
	printf("%d\n", c);
	for(auto i : range(c)) {
		printf("%d%c", ops[i] + 1, splf(i, c));
	}

}

int main() {

	const int T = read_item();
	for(auto _ : range(T)) {
		solve();
	}

	return 0;
}

/* wafdayo~~~ */
