//12252024832524
#include <cstdio>
#include <cstring>
#include <algorithm>
#define TT template<typename T>
using namespace std; 

typedef long long LL;
const int MAXN = 505;
int n;
int a[MAXN],ID[MAXN],ans[MAXN * MAXN],tot;

LL Read()
{
	LL x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
TT void Put1(T x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
TT void Put(T x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x); if(c >= 0) putchar(c);
}
TT T Max(T x,T y){return x > y ? x : y;}
TT T Min(T x,T y){return x < y ? x : y;}
TT T Abs(T x){return x < 0 ? -x : x;}

void Swap(int x)
{
	int y = x+1;
	int v1 = a[x],v2 = a[y];
	swap(a[x],a[y]);
	swap(ID[v1],ID[v2]);
	ans[++tot] = x;
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	for(int T = Read(); T ;-- T)
	{
		tot = 0;
		n = Read();
		for(int i = 1;i <= n;++ i) a[i] = Read(),ID[a[i]] = i;
		int now = 1;
		for(int i = n;i >= 2;-- i)	
		{
			if(i == 2 && ID[i] != i)
			{
				if(!now) 
				{
					if(!((n-1)&1)) ans[++tot] = n-1,ans[++tot] = 1,ans[++tot] = n-1;
					else ans[++tot] = n-2,ans[++tot] = 1,ans[++tot] = n-2;
				}
				else ans[++tot] = 1;
			}
			else if(i == 3)
			{
				while(a[1] != 1 || a[2] != 2 || a[3] != 3)
				{
					if(now) Swap(1);
					else Swap(2);
					now ^= 1;
				}
			}
			else
			{
				while(ID[i] != i)
				{
					if((ID[i] & 1) != now)
					{
						if(ID[i] >= 4)
						{
							if(!now) Swap(2);
							else Swap(1);
						}
						else
						{
							if(!now) Swap(2);
							else Swap(3);
						}
					}
					else Swap(ID[i]);
					now ^= 1;
				}
			}
		}
		Put(tot,'\n');
		for(int i = 1;i <= tot;++ i) Put(ans[i],' ');
		if(tot) putchar('\n');
	}
	return 0;
}
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
/*#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")*/
using namespace std;
using ll = long long int;
using ld = long double;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define lc v<<1
#define rc v<<1|1
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int N=5e5+10,LN=18,M=1.1e7+10,SQ=350,BS=737,inf=1e9+10;
const ll INF=1e15;
const int MH=1000696969,MOD=1000000007 /*998244353*/;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
    ll ans=1;
    while (y != 0) {
        if (y & 1) ans = ans * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return ans;
}
ll t,n,p[N];
int main(){
    fast_io;
    cin >> t;
    while(t--){
        cin >> n;
        set<ll> inv[2];
        vector<ll> ans;
        for(ll i=1; i<=n; i++) cin >> p[i];
        if(n==2){
            if(p[1]==1) cout << 0 << '\n';
            else cout << 1 << '\n' << 1 << '\n';
            continue;
        }
        for(ll i=1; i<n; i++){
            if(p[i]>p[i+1]) inv[i%2].insert(i);
        }
        for(ll i=1; !inv[0].empty() || !inv[1].empty(); i++){
            if(i>n*n) return 0;
            ll k=i%2;
            if(inv[k].empty()){
                if(k==1){
                    ans.pb(1);
                    swap(p[1],p[2]);
                    inv[1].insert(1);
                    if(p[2]<p[3]) inv[0].erase(2);
                }else{
                    ans.pb(2);
                    swap(p[3],p[2]);
                    inv[0].insert(2);
                    if(p[1]<p[2]) inv[1].erase(1);
                    if(n>=4 && p[3]<p[4]) inv[1].erase(3);
                }
            }else{
                ll j=*inv[k].rbegin();
                ans.pb(j);
                swap(p[j],p[j+1]);
                inv[k].erase(j);
                if(j>1 && p[j-1]>p[j]) inv[1-k].insert(j-1);
                if(j+2<=n && p[j+1]>p[j+2]) inv[1-k].insert(j+1);
            }
        }
        cout << ans.size() << '\n';
        for(ll i : ans) cout << i << ' ';
        cout << '\n';
    }
    return 0;
}

