#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();
}
#include<bits/stdc++.h>
using namespace std;
//#include<atcoder/all>
//using namespace atcoder;
using ll = long long;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a) (a).begin(),(a).end()
auto canMove = [](int cnt, int idx){return (cnt + idx) % 2 == 0;};
void Cout(vector<int> &ans){
    cout << ans.size() << endl;
    for(auto i : ans) cout << i + 1 << " ";
    cout << endl;
}
void Check(vector<int> &p, vector<int> &ans){
    int n = p.size(), m = ans.size();
    if(m > n * n) throw runtime_error("over the limit");
    For(i,0,n){
        if(p[i] != i){
            throw runtime_error("vector is not sorted");
        }
    }
    For(i,0,m){
        if(!canMove(i, ans[i])){
            throw runtime_error("invalid swap");
        }
    }
}
void In(int &n, vector<int> &p){
    cin >> n;
    p.resize(n);
    For(i,0,n){
        cin >> p[i];
        p[i]--;
    }
    return;
}
void Rand(int &n, vector<int> &p){
  random_device seed_gen;
  mt19937 engine(seed_gen());
  n = engine() % 500 + 1;
  p.resize(n);
  iota(ALL(p), 0);
  shuffle(ALL(p), engine);
}
void solve(){
    int n;
    vector<int> p, ans;
    In(n, p);
    // Rand(n, p);
    For(cnt,0,n*n){
        int target = -1;
        for(int i=n-1; i>-1; i--){
            if(p[i] != i){
                target = i;
                break;
            }
        }
        if(target == -1){
            Check(p, ans);
            Cout(ans);
            return;
        }
        For(i,0,n-1){
            if(p[i] == target){
                if(canMove(cnt, i)){
                    ans.push_back(i);
                    swap(p[i], p[i+1]);
                }
                else{
                    ans.push_back(cnt % 2);
                    swap(p[cnt % 2], p[cnt % 2 + 1]);
                }
                break;
            }
        }
    }
}
void Main(){
    int t;
    cin >> t;
    For(_,0,t){
        solve();
    }
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}