#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int q; cin >> q;
    while(q--){
        int n; cin >> n;
        vector<int> p(n+1);
        for(int i=1;i<=n;i++){
            cin >> p[i];
        }
        vector<int> v;
        int t=1;
        while(1){
            bool ok=true;
            for(int i=1;i<=n;i++){
                if(p[i]!=i){
                    ok=false; break;
                }
            }
            if(ok)break;
            int id;
            if(t){
                id=1;
                for(int i=1;i<n;i+=2){
                    if(p[i]>p[i+1]){
                        id=i;
                    }
                }
            }
            else{
                id=2;
                for(int i=2;i<n;i+=2){
                    if(p[i]>p[i+1]){
                        id=i;
                    }
                }
            }
            t^=1;
            swap(p[id],p[id+1]);
            v.push_back(id);
        }
        printf("%d\n",v.size());
        for(int i:v){
            printf("%d ",i);
        }
        printf("\n");
    }
}
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

void solve(){
  int N;
  cin>>N;
  vector<int> P(N);
  rep(i,N) cin>>P[i];

  rep(i,N) P[i]--;

  vector<int> trans(N,0);
  rep(i,N) trans[P[i]]=i;

  vector<int> output;
  int parity=0;
  for(int k=N-1;k>0;k--){
    int now=trans[k];
    /*cerr<<k<<" "<<parity<<"\n";
    for(auto n:P) cerr<<n<<" ";
    cerr<<"\n";*/
    while(1){
      if(now==k&&(now==N-1||P[now]+1==P[now+1])) break;

      if(now%2==parity){
        output.push_back(now);
        swap(trans[P[now]],trans[P[now+1]]);
        swap(P[now],P[now+1]);
        now++;
        parity^=1;
      }else{
        if(now-1>=0){// opt twice
          output.push_back(now-1);
          swap(trans[P[now]],trans[P[now-1]]);
          swap(P[now],P[now-1]);
          parity^=1;
          now--;

          output.push_back(now+1);
          swap(trans[P[now+1]],trans[P[now+2]]);
          swap(P[now+1],P[now+2]);
          parity^=1;
        }else{// corner case
          if(k!=1){
            output.push_back(now+1);
            swap(trans[P[now+1]],trans[P[now+2]]);
            swap(P[now+1],P[now+2]);
            parity^=1;
          }else{// yabai
            output.push_back(1);
            swap(P[1],P[2]);
            output.push_back(0);
            swap(P[0],P[1]);
            output.push_back(1);
            swap(P[1],P[2]);
            output.push_back(0);
            swap(P[0],P[1]);
            output.push_back(1);
            swap(P[1],P[2]);
            break;
          }
        }
      }
    }
  }

  /*for(auto n:P) cerr<<n<<" ";
  cerr<<"\n";*/

  cout<<output.size()<<"\n";
  rep(i,output.size()) cout<<output[i]+1<<"\n";
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int T;
  cin>>T;
  rep(i,T) solve();

  return 0;
}
