#include <cstdio>

int n;

int a[505];

int ans[250005],len;

inline void swap(int &a,int &b) {
	int tmp=a;
	a=b;
	b=tmp;
}

int p=1;

void doSwap(int pos) {
	if(p%2==1) {
		int x=0;
		if(2*x+1==pos || 2*x+2==pos) {
			x^=1;
		}
		swap(a[2*x+1],a[2*x+2]);
		ans[++len]=2*x+1;
		p++;
	}else {
		if(pos==2 || pos==3) {
			swap(a[4],a[5]);
			ans[++len]=4;
			p++;
		}else {
			swap(a[2],a[3]);
			ans[++len]=2;
			p++;
		}
	}
}

void sortSwap4() {
	if(a[4]==4) {
		return;
	}
	int pos=0;
	for(int j=1;j<=4;j++) {
		if(a[j]==4) {
			pos=j;
			break;
		}
	}
	if(pos==1) {
		if(p%2==0) {
			swap(a[2],a[3]);
			ans[++len]=2;
			p++;
		}
		swap(a[1],a[2]);
		ans[++len]=1;
		swap(a[2],a[3]);
		ans[++len]=2;
		swap(a[3],a[4]);
		ans[++len]=3;
		p++;
	}else if(pos==2) {
		if(p%2==1) {
			swap(a[3],a[4]);
			ans[++len]=3;
			p++;
		}
		swap(a[2],a[3]);
		ans[++len]=2;
		swap(a[3],a[4]);
		ans[++len]=3;
	}else if(pos==3) {
		if(p%2==0) {
			swap(a[2],a[3]);
			ans[++len]=2;
			swap(a[3],a[4]);
			ans[++len]=3;
			swap(a[2],a[3]);
			ans[++len]=2;
			swap(a[3],a[4]);
			ans[++len]=3;
		}else {
			swap(a[3],a[4]);
			ans[++len]=3;
			p++;
		}
	}
}

int main() {
	int T;
	scanf("%d",&T);
	while(T--) {
		scanf("%d",&n);
		for(int i=1;i<=n;i++) {
			scanf("%d",&a[i]);
		}
		if(n==2) {
			if(a[1]!=1) {
				swap(a[1],a[2]);
				printf("1\n1\n");
			}else {
				printf("0\n\n");
			}
			continue;
		}
		len=0;
		p=1;
		for(int i=n;i>=5;i--) {
			int pos=0;
			for(int j=1;j<=n;j++) {
				if(a[j]==i) {
					pos=j;
					break;
				}
			}
			if((pos%2==0 && p%2==1) || (pos%2==1 && p%2==0)) {
				doSwap(pos);
			}
			//printf("Value at position %d: %d\n",pos,a[pos]);
			for(int j=pos;j<i;j++) {
				swap(a[j],a[j+1]);
				ans[++len]=j;
				p++;
			}
			//printf("Stage 1 level %d: ",i);
		}
		//Sort 1-4
		if(n>=4) {
			sortSwap4();
		}
		//Sort 1-3
		while(a[1]!=1 || a[2]!=2 || a[3]!=3) {
			if(p%2==1) {
				swap(a[1],a[2]);
				ans[++len]=1;
				p++;
			}else {
				swap(a[2],a[3]);
				ans[++len]=2;
				p++;
			}
		}
		printf("%d\n",len);
		for(int i=1;i<=len;i++) {
			printf("%d ",ans[i]);
		}
		printf("\n");
	}
	return 0;
}
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
using namespace std;

/* Defines begin */
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL) , cout.tie(NULL), cout<<fixed<<setprecision(20);
#define w1 solve();
#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define tr(it, x) for(auto it = x.begin(); it != x.end(); it++) //traversal for vector, set, pair, map
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
#define cinvi0(a,n) vi a(n); for0(i,n) { cin>>a[i]; }
#define cinvs0(s,n) vs s(n); for0(i,n) { cin>>s[i]; }
#define cinvd0(a,n) vd a(n); for0(i,n) { cin>>a[i]; }
//short hand for usual tokens
#define pb push_back
#define mp make_pair
#define double long double
#define fi first 
#define se second
#define sz(x) ((int)(x).size())
#define endl '\n'

//debugger
#define LOCAL
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
/* Defines end */

/* Constants begin */
const long long inf = 2e18 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-7;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Typedef begin */
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pi;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<string> vs;
/* Typedef end */

/* Template begin */
//Short hand for token
template <class T> using V = vector<T>; // all type of vector regardless of class
template <class T> using VV = V<V<T>>; // all type of vector inside of vector regardless of class


//Debugger stuff
    template <typename Arg1>
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << ": " << arg1 << endl;
}

    template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}
/* Template end */



//Set reminder 
// x << b is equal to x * (2)^b
// x >> b is equal to x / (2)^b
// bitset<8>(x) is equal to binary number of specific x



void solve()
{
    int n; cin >> n;
    int cnt = 0;
    int temp = 0;
    while(temp < n)
    {
        if(temp <= n)
            temp += 100;
        cnt++;
    }
    cout << cnt << "\n";

}



auto main() -> int
{
    fastio
        w1
        return 0;
}

