#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define all(x) x.begin(),x.end()
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
    os << "[";
    for (ll i=0; i < v.size(); ++i) {
        os << v[i];
        if (i != v.size() - 1)
            os << ", ";
    }
    os << "]";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v){
    os << "{";
    for (auto it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}";
    return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v){
    os<<"{";
    for (auto it : v){
        os << it.first << " : "
           << it.second ;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}";
    return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v){
    os << "(";
    os << v.first << ", "
       << v.second << ")";
    return os;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        vector<ll> arr(n);
        REP(i,n){
            cin>>arr[i];
            arr[i]--;
        }
       // cout<<arr<<endl;
        if(n==2){
            if(arr[0]==0){
                cout<<0<<endl;
            }
            else{
                cout<<1<<endl;
                cout<<1<<endl;
            }
            continue;
        }
        ll turn=0;
        vector<ll> ans;
        for(ll elem=n-1;elem>2;elem--){
            ll pos;
            for(ll i=0;i<=elem;i++){
                if(arr[i]==elem){
                    pos=i;
                    break;
                }
            }
            if(pos==elem) continue;
            if((pos & 1)==turn){
                for(ll i=pos;i<elem;i++){
                    ans.pb(i);
                    swap(arr[i],arr[i+1]);
                    turn^=1;
                }
            }
            else{
                ll ideal=-1;
                for(ll j=0;j<elem;j++){
                    if((j & 1)==turn){
                        if(j+1!=pos){
                            ideal=j;
                            break;
                        }
                    }
                }
                if(ideal!=-1){
                    ans.pb(ideal);
                    swap(arr[ideal],arr[ideal+1]);
                    turn^=1;
                    for(ll i=pos;i<elem;i++){
                        ans.pb(i);
                        swap(arr[i],arr[i+1]);
                        turn^=1;
                    }
                }
                else{
                    ans.pb(pos-1);
                    swap(arr[pos-1],arr[pos]);
                    turn^=1;
                    ans.pb(pos);
                    swap(arr[pos],arr[pos+1]);
                    turn^=1;
                    for(ll i=pos-1;i<elem;i++){
                        ans.pb(i);
                        swap(arr[i],arr[i+1]);
                        turn^=1;
                    }
                }
            }
        }
       // cout<<arr<<endl;
       // cout<<turn<<endl;
        vector<ll> aux(arr.begin(),arr.begin()+3);
        vector<ll> tar{0,1,2};
        while(aux!=tar){
            if(turn & 1){
                ans.pb(1);
                swap(aux[1],aux[2]);
                turn^=1;
            }
            else{
                ans.pb(0);
                swap(aux[0],aux[1]);
                turn^=1;
            }
        }
        cout<<ans.size()<<endl;
        for(auto & x:ans){
            cout<<x+1<<" ";
        }
        cout<<endl;

    }

}

#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;
}


