#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
const int N=5e6+5;
const int M=1e5+5;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-8;
const long double pi=acos(-1.0L);
#define ls (i<<1)
#define rs (i<<1|1)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
LL read()
{
    LL x=0,t=1;
    char ch;
    while((ch=getchar())<'0'||ch>'9') if(ch=='-') t=-1;
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+ch-'0'; ch=getchar(); }
    return x*t;
}
int a[N],ans[N];
int main()
{
    int T=read();
    while(T--)
    {
        //并不需要考虑去将每一个数字归位，而是可以直接考虑减少逆序对(交换相邻的逆序数字)
        int n=read(),tot=0;
        for(int i=1;i<=n;i++) a[i]=read();
        for(int k=0;;k^=1){
            int flag=0;
            for(int i=1;i<n;i++)
                if(a[i]>a[i+1]) flag=1;
            if(!flag) break;
            int i;
            for(i=k+1;i<n&&a[i]<a[i+1];i+=2);
            if(i>=n) i-=2;
            ans[++tot]=i;
            swap(a[i],a[i+1]);
        }
        printf("%d\n",tot);
        for(int i=1;i<=tot;i++) printf("%d%c",ans[i],i==tot?'\n':' ');
    }

    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

void testcase(){
  int N; cin >> N;
  vector<int> A(N); rep(i,N) cin >> A[i];
  vector<int> ans;
  int turn = 0;
  auto op = [&ans,&A,&turn](int p)->void{
    swap(A[p],A[p+1]);
    ans.push_back(p+1);
    turn ^= 1;
  };

  while(A.size() >= 4){
    int p = -1;
    rep(i,A.size()) if(A[i] == A.size()) p = i;
    if(p%2 != turn){
      int x = -1;
      if(p == 0) op(1);
      if(p == 1) op(2);
      if(p == 2){ op(1); op(2); p=1; }
      if(p >= 3 && p%2 == 1) op(0);
      if(p >= 4 && p%2 == 0) op(1);
    }
    while(p != A.size()-1){
      op(p++);
    }
    A.pop_back();
  }

  vector<int> tg(A.size());
  rep(i,tg.size()) tg[i] = i+1;
  while(tg != A) op(turn);

  cout << ans.size() << "\n";
  rep(i,ans.size()){
    if(i) cout << " ";
    cout << ans[i];
  }
  cout << "\n";
}

int main(){
  int T; cin >> T;
  while(T--) testcase();
  return 0;
}



struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;


