#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef map<ll, ll> ml;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {return (a % b + b) % b;}
ll quo(ll a, ll b) {return (a - mod(a, b)) / b;}
template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;}
template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const ld eps = 1e-9;
const char newl = '\n';

ll t, n;
bool f;
vl p, inv, ans;

void op(ll num) {
  ans.push_back(num);
  swap(p[num], p[num+1]);
  inv[p[num]] = num;
  inv[p[num+1]] = num+1;
  f = !f;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> t;
  rep(_, t) {
    cin >> n;
    f = 0;
    p = vl(n);
    inv = vl(n);
    ans = vl(0);
    rep(i, n) {
      cin >> p[i];
      p[i]--;
      inv[p[i]] = i;
    }
    if(n >= 5) {
      rep3(i, n-1, 4) {
        if(inv[i] == i) continue;
        else if(f ^ (inv[i] & 1)) {
          if(inv[i] >= 3) op(inv[i] - 3);
          else op(inv[i] + 1);
        }
        while(inv[i] != i) op(inv[i]);
      }
    }
    if(n >= 4 && p[3] != 3) {
      if(f) op(1);
      if(inv[3] == 0) {op(0); op(1); op(2);}
      if(inv[3] == 1) {op(2); op(1); op(2);}
      if(inv[3] == 2) {op(2);}
    }
    while(p[0] != 0 || p[1] != 1) {
      if(f) op(1);
      else op(0);
    }
    cout << ans.size() << newl;
    rep(i, ans.size()) cout << ans[i] + 1 << ' ';
    cout << newl;
  }
  return 0;
}
#include <iostream>
#include <vector>
using namespace std;

void sub(int n, int *p, vector<int> &ans, int k){
    for(int c = 0; c < 20; c++){
        bool f = true;
        for(int i = n - 3; i < n; i++){
            if(p[i] != i) f = false;
        }
        if(f) return;
        else{
            if(k % 2 == (n - 2) % 2){
                ans.push_back(n - 2);
                swap(p[n - 2], p[n - 1]);
                k++;
            }
            else{
                ans.push_back(n - 3);
                swap(p[n - 3], p[n - 2]);
                k++;
            }
        }
    }
}

void query(int n, int *p){
    if(n == 2){
        if(p[0] == 0){
            cout << 0 << endl;
        }
        else{
            cout << 1 << endl << 1 << endl;
        }
        return;
    }
    vector<int> ans;
    int k = 0;
    for(int c = 0; c < n - 3; c++){
        for(int i = c; i < n; i++){
            if(i == c) continue;
            if(p[i] == c){
                if((i - 1) % 2 != k % 2){
                    if(i != n - 1){
                        ans.push_back(i);
                        swap(p[i], p[i + 1]);
                        k++;
                        ans.push_back(i - 1);
                        swap(p[i - 1], p[i]);
                        k++;
                        i++;
                    }
                    else{
                        ans.push_back(i - 2);
                        swap(p[i - 2], p[i - 1]);
                        k++;
                    }
                }
                for(int j = i - 1; j >= c; j--){
                    ans.push_back(j);
                    swap(p[j], p[j + 1]);
                    k++;
                }
            }
        }
    }
    sub(n, p, ans, k);
    cout << (int)ans.size() << endl;
    for(int i : ans) cout << i + 1 << " ";
    cout << endl;
}

int main()
{
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        int p[505];
        for(int i = 0; i < n; i++){
            cin >> p[i];
            p[i]--;
        }
        query(n, p);
    }
}
