#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

void solve(int _rot){
   // printf("Case #%d: ",_rot);
   int n;
   cin>>n;
   vector<int> a(n);
   rep(i,0,n)cin>>a[i];
   if(n==2){
      if(a[0]!=1){
         puts("1\n1");
      }
      else{
         puts("0");
      }
      return;
   }

   map<int,int> pos;
   rep(i,0,n)pos[a[i]]=i;
   vector<int> res;
   auto process=[&](int i){
      res.push_back(i+1);
      swap(a[i],a[i+1]);
      swap(pos[a[i]],pos[a[i+1]]);
   };

   bool flip=1;
   rep(i,0,n-3){
      int from=pos[i+1];
      if(flip+(from&1)==1){ //not match
         int to;
         if(from>=n-2){
            to=i/2*2;
            if(!flip)to++;
            if(to<i)to+=2;
            if(to==from or to==from-1)to+=2;
         }
         else{
            to=n/2*2;
            if(!flip)to++;
            while(to>=n-1)to-=2;
            if(to==from or to==from-1)to-=2;
         }
         process(to);
         flip^=1;
      }
      {
         while(from>i){
            process(from-1);
            from--;
            flip^=1;
         }
      }
   }
   for(;;){
      int from;
      if(flip)from=n/2*2-2;
      else from=n/2*2-1;
      if(from==n-1)from-=2;
      process(from);
      if(a[n-3]==n-2 and a[n-2]==n-1 and a[n-1]==n)break;
      flip^=1;
   }

   cout<<res.size()<<'\n';
   for(auto& x:res)cout<<x<<'\n';
}

int main(){
   int t; scanf("%d",&t);
   rep(rot,0,t)solve(rot+1);
   return 0;
}
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    vector<int> inv(n);
    rep(i,n){
        inv[a[i]] = i;
    }
    vector<int> res;
    int k = 0;
    rep(i,n){
        while(k!=n&&inv[k]==k){
            k++;
        }
        if(k==n)break;
        res.push_back(inv[k]-1);
        int id = inv[k]-1;
        swap(a[id],a[id+1]);
        inv[a[id]] = id;
        inv[a[id+1]] = id+1;
    }
    bool ok = 1;
    rep(i,n){
        if(a[i]!=i)ok = 0;
    }
    if(ok&&(int)res.size()==n-1){
        rep(i,n-1){
            cout << res[i]+1 << "\n";
        }
    }else{
        cout << -1 << endl;
    }
    return 0;
}