#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        int N;cin>>N;
        vector<int> p(N+1);
        for(int i=0;i<N;i++) cin>>p[i+1];
        vector<int> ans;
        
        if(N==2){
            if(p[1]==1){
                cout<<0<<endl;
                cout<<endl;
            }else{
                cout<<1<<endl;
                cout<<1<<endl;
            }
            continue;
        }
        
        int t=1;
        for(int i=1;i<=N-3;i++){
            int pos=-1;
            for(int j=i;j<=N;j++){
                if(p[j]==i){
                    pos=j;
                    break;
                }
            }
            if(pos==i){
                for(int j=i+1;j<N;j++){
                    if((j&1)==(t&1)){
                        ans.push_back(j);
                        swap(p[j],p[j+1]);
                        t++;
                        break;
                    }
                }
            }else{
                if((pos&1)==(i&1)){
                    for(int j=i;j<N;j++){
                        if((j&1)==(t&1)&&j!=pos){
                            ans.push_back(j);
                            swap(p[j],p[j+1]);
                            t++;
                            break;
                        }
                    }
                }
                
                for(int j=pos-1;j>=i;j--){
                    ans.push_back(j);
                    swap(p[j],p[j+1]);
                    t++;
                }
            }
        }
        
        if(p[N-2]==N-2){
            if(p[N-1]==N){
                ans.push_back(N-2);
                ans.push_back(N-1);
                ans.push_back(N-2);
                ans.push_back(N-1);
                ans.push_back(N-2);
            }
        }else{
            if(p[N-1]==N-2){
                ans.push_back(N-2);
                swap(p[N-2],p[N-1]);
                t++;
            }else{
                ans.push_back(N-2);
                swap(p[N-2],p[N-1]);
                t++;
                
                ans.push_back(N-1);
                swap(p[N-1],p[N]);
                t++;
                
                ans.push_back(N-2);
                swap(p[N-2],p[N-1]);
                t++;
            }
            
            if(p[N-1]==N){
                ans.push_back(N-1);
            }
        }
        
        cout<<si(ans)<<endl;
        for(int a:ans) cout<<a<<" ";
        cout<<endl;
    }
}

#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long> 
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int t, n[250];
vector<int> v[250], ans[250];

int main() {
    ci(t);
    rep(i, t) {
        ci(n[i]);
        rep(j, n[i]) {
            int p;
            ci(p);
            v[i].epb(p - 1);
        }
    }
    rep(i, t) {
        if (n[i] == 2) {
            if (v[i][0]) ans[i].epb(1);
            continue;
        }
        vector<int> memo(n[i]);
        rep(j, n[i]) memo[v[i][j]] = j;
        int cnt = 0;
        rep(j, n[i] - 3) {
            int a = memo[j];
            if (a == j) continue;
            if (cnt % 2 == a % 2) {
                cnt++;
                if (a > j + 1) {
                    swap(v[i][a - 2], v[i][a - 1]);
                    swap(memo[v[i][a - 2]], memo[v[i][a - 1]]);
                    ans[i].epb(a - 1);
                }
                else if (a + 3 < n[i]) {
                    swap(v[i][a + 2], v[i][a + 3]);
                    swap(memo[v[i][a + 2]], memo[v[i][a + 3]]);
                    ans[i].epb(a + 3);
                }
                else {
                    ans[i].epb(a + 1);
                    ans[i].epb(a);
                    ans[i].epb(a + 1);
                    swap(v[i][a - 1], v[i][a + 1]);
                    swap(memo[v[i][a - 1]], memo[v[i][a + 1]]);
                    cnt += 2;
                }
            }
            for (int k = a - 1; k >= j; k--) {
                memo[v[i][k]]++;
                swap(v[i][k], v[i][k + 1]);
                cnt++;
                ans[i].epb(k + 1);
            }
            memo[j] = j;
        }
        for (bool j = (cnt + n[i] + 1) % 2; v[i][n[i] - 3] != n[i] - 3 ||
                                        v[i][n[i] - 2] != n[i] - 2 ||
                                        v[i][n[i] - 1] != n[i] - 1; j = !j) {
            swap(v[i][n[i] - 3 + j], v[i][n[i] - 2 + j]);
            ans[i].epb(n[i] - 2 + j);
        }
    }
    rep(i, t) {
        co(ans[i].size());
        rep(j, ans[i].size() - 1) cout << ans[i][j] << " ";
        if (ans[i].empty()) cout << endl;
        else cout << ans[i].back() << endl;
    }
    return 0;
}
