#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void solve() {
  int n;
  cin >> n;
  vector<int> p(n), pos(n);
  for(int i = 0; i < n; i++) {
    cin >> p[i]; p[i]--;
    pos[p[i]] = i;
  }
  int cur = 0;
  vector<int> ans;
  int op[5] = {2, 1, 2, 1, 2};
  for(int i = 0; i < n; i++) {
    if(pos[i] != i) {
      int cpos = pos[i];
      if(cpos % 2 == cur % 2) {
        if(cpos - 2 == i - 1) {
          for(int j = 0; j < 5; j++) {
            ans.pb(cpos - op[j]); cur++;
            swap(p[cpos - op[j]], p[cpos - op[j] + 1]);
            swap(pos[p[cpos - op[j]]], pos[p[cpos - op[j] + 1]]);
          }
          continue;
        }
        ans.pb(cpos - 2); cur++;
        swap(p[cpos - 2], p[cpos - 1]);
        swap(pos[p[cpos - 2]], pos[p[cpos - 1]]);
        ans.pb(cpos - 1); cur++;
        swap(p[cpos - 1], p[cpos]);
        swap(pos[p[cpos - 1]], pos[p[cpos]]);
        for(int j = cpos - 2; j >= i; j--) {
          swap(p[j], p[j + 1]);
          swap(pos[p[j]], pos[p[j + 1]]);
          ans.pb(j); cur++;
        }
      } else {
        for(int j = cpos - 1; j >= i; j--) {
          ans.pb(j); cur++;
          swap(p[j], p[j + 1]);
          swap(pos[p[j]], pos[p[j + 1]]);
        }
      }
    }
  }
  // for(auto& x : p) cout << x + 1 << ' ';
  // cout << '\n';
  cout << ans.size() << '\n';
  // for(int i = 0; i < ans.size(); i++) {
  //   if(i % 2 != ans[i] % 2) cout << "BAD\n";
  // }
  for(auto& x : ans) cout << x + 1 << ' ';
  cout << '\n';
}
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int t = 0;

  cin >> t;

  while(t--) solve();

  return 0;
}
/*

*/

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

void solve(){
  int N; cin >> N;
  vector<int> A(N);
  rep(i,N){
    cin >> A[i];
  }
  vector<int> G=A;
  sort(all(G));
  int cnt = 0;
  vector<int> ans;
  while(G!=A){
    if(cnt%2==0){
      int ch = 0;
      for(int i=0;i+1<N;i+=2){
        if(A[i]>A[i+1]){
          ch = i;
          //break;
        }
      }
      ans.pb(ch);
      swap(A[ch], A[ch+1]);
    }
    else{
      int ch = 1;
      for(int i=1;i+1<N;i+=2){
        if(A[i]>A[i+1]){
          ch=i;
          //break;
        }
      }
      ans.pb(ch);
      swap(A[ch],A[ch+1]);
    }
    cnt++;
  }
  cout << cnt << endl;
  rep(i,sz(ans)){
    if(i) cout << " ";
    cout << ans[i]+1;
  }
  cout << endl;
}

int main(){
  int T; cin >> T;
  while(T--){
    solve();

  }
  return 0;
}
