#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 2e5 + 10;

int a[N], res[N], pos[N];

void Swap(int p, int &idx) {
	swap(pos[a[p]], pos[a[p + 1]]);
	swap(a[p], a[p + 1]);
	res[idx++] = p;
}

void solve() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		pos[a[i]] = i;
	}
	int idx = 1;
	for(int i = n; i >= 1; i--) {
		if(a[i] == i) continue;
		while(idx % 2 != pos[i] % 2) {
			if(idx & 1) Swap(1, idx);
			else Swap(2, idx);
		}
		while(pos[i] != i) {
			Swap(pos[i], idx);
		}
	}
	printf("%d\n", idx - 1);
	for(int i = 1; i < idx; i++) {
		printf("%d ", res[i]);
	}
	puts("");
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE

    int t; cin >> t; while(t--)
    solve();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define read read1<ll>()
# define Type template<typename T>
Type T read1(){
	T t=0;
	char k;
	bool vis=0;
	do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9');
	while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar();
	return vis?-t:t;
}
# define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout)
int s,a[505],b[505],pr[505*505];bool ty;
void Swap(int x,int y){b[a[x]]=y;b[a[y]]=x;swap(a[x],a[y]);pr[++*pr]=x;ty^=1;}
void Swap2(int x){Swap(x-1,x);Swap(x,x+1);Swap(x-1,x);Swap(x,x+1),Swap(x-1,x);}
int main(){
	for(int T=read;T--;){
		s=read;*pr=0;ty=1;
		for(int i=1;i<=s;++i)b[a[i]=read]=i;
		for(int i=1;i<s-1;++i){
			if(b[i]==i)continue;
			if((b[i]^ty)&1)
				for(int j=b[i]-1;j>=i;--j)Swap(j,j+1);
			else{
				int w=b[i]-1;
				if(w!=i)Swap(w-1,w);
				else if(w==s-3){
					Swap(w+1,w+2);
					Swap(w+2,w+3);
					Swap(w+1,w+2);
					w=s-1;
				}else if(w==s-2){Swap2(i);w=i-1;}
				else Swap(w+3,w+4);
				for(int j=w;j>=i;--j)Swap(j,j+1);
			}
		}if(a[s-1]>a[s])
			if((b[s-1]^ty)&1)Swap(b[s-1]-1,b[s-1]);
			else Swap2(s-1);
		printf("%d\n",*pr);
		for(int i=1;i<=*pr;++i)printf("%d ",pr[i]);
		putchar('\n');
	}
	return 0;
}/*

      x
1 3 2 5 4
a c b
c a b
c b a
b c a
b a c
a b c
*/