#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;
constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 
ll gcd(ll x, ll y) {	if (x == 0) return y;	return gcd(y%x, x);}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }
ll modpow(ll a, ll n, ll p) {	if(n==0) return (ll)1;  if (n == 1) return a % p;  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;  ll t = modpow(a, n / 2, p);  return (t * t) % p;}
ll modinv(ll a, ll m) {	if(m==0)return (ll)1;	ll b = m, u = 1, v = 0;	while (b) {		ll t = a / b;		a -= t * b; swap(a, b);		u -= t * v; swap(u, v);	}	u %= m;	if (u < 0) u += m;	return u;}
ll fac[MAX], finv[MAX], inv[MAX]; 
void COMinit() {	fac[0] = fac[1] = 1;	finv[0] = finv[1] = 1;	inv[1] = 1;	for (int i = 2; i < MAX; i++) {		fac[i] = fac[i - 1] * i % MOD;		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;		finv[i] = finv[i - 1] * inv[i] % MOD;	}}
ll COM(ll n, ll k) {	if (n < k) return 0;	if (n < 0 || k < 0) return 0;	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll com(ll n,ll m){   if(n<m || n<=0 ||m<0){		return 0;	}	if( m==0 || n==m){		return 1;	}	ll k=1;	for(ll i=1;i<=m;i++){       k*=(n-i+1); 	   k%=MOD;	   k*=modinv(i,MOD);	   k%=MOD;	}	return k;}
ll rad(ll u, ll p){ ll cnt=0;	while(u%p==0){		u/=p;		cnt++;	}	return cnt;}
////////////////////////////////////////////////////////////////////



int main() {
 ios::sync_with_stdio(false);

ll tt;
cin>>tt;

ll num[550];
  ll dis[550];
for(int i=0;i<=501;i++){
	num[i]=i;
}
  for(int i=0;i<=500;i++){
    dis[i]=i;
  }
rep(qq,tt){
	ll cnt=0;
ll n;
cin>>n;



vector<ll> v;
rep(i,n){
	ll t;
	cin>>t;
	v.pb(t);
}

if(n==1){cout<<0<<endl;
continue;}
if(n==2){
	if(v[0]==1){cout<<0<<endl;}
	else{
		cout<<1<<endl;
		cout<<1<<endl;
	}
	continue;
}

for(ll i=0;i<n;i++){
num[i+1]=v[i];
 dis[v[i]]=i+1;
}

vector<ll> ans;

 
ll fin=0;
for(ll i=1;i<=n;i++){
if(num[i]==i && i!=n-2)continue;
if(i==n-2){
	
	while(fin==0){
		cnt++;
	if(cnt%2==n%2){
		ll u=num[n-2];
		     dis[num[n-1]]=n-2;
      dis[num[n-2]]=n-1;
		num[n-2]=num[n-1];
		num[n-1]=u;
 
		ans.pb(n-2);
	}
	else{
		ll u=num[n-1];
		  dis[num[n-1]]=n;
      dis[num[n]]=n-1;
		num[n-1]=num[n];
		num[n]=u;
     
		ans.pb(n-1);
	}
if(dis[n-2]==n-2 && dis[n-1]==n-1 && dis[n]==n){fin=1;}

}

}
if(fin==1)break;

while(num[i]!=i){
cnt++;
  



if(cnt%2==dis[i]%2){
	if(cnt%2==n%2){
		ll u=num[n-2];
		     dis[num[n-1]]=n-2;
      dis[num[n-2]]=n-1;
		num[n-2]=num[n-1];
		num[n-1]=u;
 
		ans.pb(n-2);
	}
	else{
		ll u=num[n-1];
		  dis[num[n-1]]=n;
      dis[num[n]]=n-1;
		num[n-1]=num[n];
		num[n]=u;
     
		ans.pb(n-1);
	}

}
else{
ll u=num[dis[i]];
  num[dis[i]]=num[dis[i]-1];
  num[dis[i]-1]=u;
  dis[i]--;
  dis[num[dis[i]+1]]++;

    
ans.pb(dis[i]);

}


}


}


cout<<cnt<<endl;
for(int i=1;i<ans.size();i++){
	cout<<ans[i-1]<<" ";
}
cout<<ans[cnt-1]<<endl;


}



return 0;
}



#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
//#include <unistd.h>
void solve(){
        int n;
        cin>>n;
        V<int> a(n);
        for(int i=0;i<n;i++){
                cin>>a[i];
                a[i]--;
        }
        int t=0;
        V<int> ans;
        V<bool> ok(n,false);
        while(1){
              bool ok=true;
                for(int j=0;j<n;j++){
                        if(a[j]<j){
                              ok=false;
                               if(j%2==t){
                                      if(t==0){
                                             swap(a[0],a[1]);
                                             ans.emplace_back(1);
                                      }else{
                                            swap(a[1],a[2]);
                                            ans.emplace_back(2);
                                      }
                                      t^=1;
                               }
                               while(a[j]<j){
                                       swap(a[j-1],a[j]);
                                       ans.emplace_back(j);
                                       j--;
                                       t^=1;
                               }
                               break;
                        }
                }
                if(ok)break;
        }
      //  print(a);
        cout<<ans.size()<<"\n";
        print(ans);
}
int main(){
      int t;
      cin>>t;
      while(t--)solve();
}