
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define endl "\n"
#define fill(A,x) memset(A,x,sizeof A);

void solve()
{ 
  int n;
    cin>>n;
	vi pos(n+5),ar(n+5);
	vi ans;
    for(int i=1;i<=n;i++)
    {
        cin>>ar[i];
        pos[ar[i]]=i;
    }
    if(n==2)
    {
        if(pos[1]==1)cout<<0<<endl;
        else {cout<<1<<endl;cout<<1;}
        cout<<endl;
        return;
    }
    
    
    for(int i=n;i>0;i--)
    {
        if(i>n||pos[i]==i)
        continue;
        int c=pos[i];
        if(c%2!=(ans.size())%2)
        {
            while(pos[i]!=i)
            {
                int x=ar[pos[i]+1];
                ar[pos[i]]=x;ar[pos[i]+1]=i;
                ans.pb(pos[i]);
                pos[i]++;pos[x]--;
            }
        }
        else
        {
            if(c%2==0)
            {
                ans.pb(1);
                ans.pb(2);
                ans.pb(1);
                pos[ar[1]]+=2;pos[ar[3]]-=2;
                swap(ar[1],ar[3]);
                i++;
            }
            else
            {
                ans.pb(2);
                ans.pb(1);
                ans.pb(2);
                pos[ar[1]]+=2;pos[ar[3]]-=2;
                swap(ar[1],ar[3]);
                i++;
                i++;
            }
        }
    }
    
    
    int x=ans.size();
    cout<<x<<endl;
    
    
    for(auto it:ans)cout<<it<<" ";
    cout<<endl;
}

signed main()
{ 
    boost
    int test=0,t;
    cin >> t ;
    //t=1;
   while(test++ <t){
	//   cout<<"Case #"<<test<<": ";
	   solve();}
  
}
#line 1 "/workspaces/compro/lib/template.hpp"


#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "main.cpp"

double solve(ll N, const std::vector<long long> &A) {
  ll sum = accumulate(ALL(A), 0LL);
  auto E = [&](double x, double k, double sum) { return x * 2 * k + sum - x * N; };

  double ans = 1e20;
  REP(k, N + 1) {
    if (k == 0) {
      chmin(ans, E(0, 0, sum) / N);
      sum -= A[k];
    } else if (k == N) {
      chmin(ans, E((double)A[N - 1] / 2, N, sum) / N);
    } else {
      chmin(ans, E((double)A[k - 1] / 2, k, sum) / N);
      chmin(ans, E((double)A[k] / 2, k, sum) / N);
      sum -= A[k];
    }
  }

  return ans;
}

// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
  int N;
  std::cin >> N;
  std::vector<long long> A(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }
  sort(ALL(A));
  auto ans = solve(N, A);
  std::coutd(10) << ans << std::endl;
  return 0;
}
