//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#include<set>
#include <array>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound

#define si(x) int(x.size())
#define sum_all(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
const double pi = 2 * acos(0.0);
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, -1, 0, 1 };

const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 };
const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 };

ll min(ll a,ll b)
{
    if(a<b)return a;
    return b; 
}
ll max(ll a,ll b)
{
    if(a>b)return a;
    return b; 
}
ll ceil1(ll a,ll b)
{
    return(a+b-1)/b;
}
void read(vector<ll> & arr)
{
  for(ll i=1;i<si(arr);i++)
    cin >> arr[i];

}

void read_graph(vector<vector<ll>>& g, ll m)
{
  while(m--)
  {
    ll x,y; cin >> x>> y ;
    x--,y--; 
    g[x].pb(y);
    g[y].pb(x);
  }
}


bool sorted(vector<ll> &arr)
{
  int n=si(arr)-1; 
  if(arr[n]>arr[n-1] and arr[n-1]>arr[n-2]) return true;
  return false ;

}
void brute(vector<int> &ans, vector<ll> &arr, ll c)
{
  
   int n=si(arr)-1; 
   int e=n-2;
   int o=n-1;
   if(e%2!=0) 
   	swap(o,e);
  while(sorted(arr)==false)
  {
  	if(c%2==0)
  	{
        ans.pb(e);
        swap(arr[e],arr[e+1]);
        c++;
  	}
  	else 
  	{
  		ans.pb(o);
  		swap(arr[o],arr[o+1]);
  		c++;
  	}
  }
  return ; 

}
void solve()
{
 
  ll n;
  cin >> n;
   
  
   vector<ll>a(n+1);
   read(a);
   if(n==2)
   {
   	 if(a[1]==1) 
   	 {
   	 	 cout << 0 << endl;
   	 	 return ;
   	 }
   	 else 
   	 {
   	 	cout <<1 << endl << 1 << endl;
   	 	return ; 
   	 }
   }
   

   ll c=1;
   vector<int> ans; 
   for(ll i=1;i<=n;i++)
   {
    ll i1=i; 
    for(ll j=1;j<=n;j++)
    	if(a[j]==i) 
    	{
    		i1=j;
    		break; 
    	}
    	 
       if(i1==i) continue; 
       for(ll j=i1;j>i;j--)
       {
       	if((j-1)%2==1)
       	{
          if(c%2==1)
          {
          	ans.pb(j-1);
          	swap(a[j-1],a[j]);
          	c++;
          }
          else 
          {
            
              if(j-i>=2)
          {
          	swap(a[j-2],a[j-1]);
          	ans.pb(j-2);
          	c++;
          	j++;
          } else if(j<=n-1)
            {
            	ans.pb(j);
            	swap(a[j],a[j+1]);
            	c++;
            	j+=2;
            }
            else 
            {
             brute(ans,a,c);
            }
          }
       	}
       	else 
       	{
         if(c%2==0)
         {
         	ans.pb(j-1);
            swap(a[j-1],a[j]);
            	c++;
         }
         else 
         {

         	if(j-i>=2)
          {
          	swap(a[j-2],a[j-1]);
          	ans.pb(j-2);
          	c++;
          	j++;
          } 
          else if(j<=n-1)
          {
          	swap(a[j+1],a[j]);
          	ans.pb(j);
          	c++;
          	j+=2;
          }
          

          else 
          {
          	brute(ans,a,c);
          }
         }
       	}
       }

   }

   for(int i=0;i<si(ans);i++)
   {
   	assert(ans[i]%2==(i+1)%2);
   }
for(int i=1;i<=n;i++) assert(a[i]==i);
   assert(si(ans)<=n*n);
   cout << si(ans) << endl;
   for(auto a: ans) cout << a<< " ";
   	cout << endl; 

   
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t; cin >> t; while (t--)
    solve();

}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

template<class T>
vector<T> make_vec(size_t a){
	return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
	return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T; cin>>T;
    while(T--){
        int N; cin>>N;
        vi p(N);
        rep(i,N) cin>>p[i], p[i]--;

        vi ans;

        auto solve = [&](int x){
            int idx=-1;
            FOR(i,x,N-1)if(p[i]==x) idx=i;

            assert(idx!=-1);

            if (idx==x){
                if (N-x>=3){
                    ans.pb(idx); swap(p[idx],p[idx+1]);
                    ans.pb(idx+1); swap(p[idx+1],p[idx+2]);
                    ans.pb(idx); swap(p[idx],p[idx+1]);
                    ans.pb(idx+1); swap(p[idx+1],p[idx+2]);
                    ans.pb(idx); swap(p[idx],p[idx+1]);
                }
                return;
            }
            if (idx%2==x%2){
                ans.pb(x);
                swap(p[x],p[x+1]);
            }

            while(idx!=x){
                ans.pb(idx-1);
                swap(p[idx-1],p[idx]);
                idx--;
            }
        };

        rep(i,N) solve(i);

        int M = ans.size();
        cout<<M<<"\n";
        rep(i,M){
            cout<<ans[i]+1<<" \n"[i==M-1];
        }
    }
    return 0;
}
