
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */
#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

using ld=long double;
const ld PI = acos((ld)-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) ld d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<ld, ld>;
using vd= vector<ld>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

/*
 * Consider 1,3,2
 * We would like to choose pos=2 to swap 3,2, but that not possible in 
 * first operation.
 * So we must choose pos=1, which yields 3,1,2
 * Then we must choose pos=2, 3,2,1
 * 2,3,1
 * 2,1,3
 * 1,2,3
 * So, we swap the smallest inversion if possible, else the next position,
 * else the previous position.
 * How to maintain the "next inversion"?
 * -> Just use a pointer to current element, go left to right.
 *
 * How do we go left to right?
 * Invariant: a[0]..a[i] is sorted
 */
void solve() {
    cini(n);
    cinai(a,n);

    int i=0;
    while(i+1<n && a[i]<a[i+1])
        i++;

    int op=0;
    vi ans;
    while(i+1<n) {

        if(a[i]>a[i+1] && (i%2==op)) {
            swap(a[i], a[i+1]);
            ans.push_back(i+1);
            if(i>0)
                i--;
        } else if(i+2<n) {
            swap(a[i+1], a[i+2]);
            ans.push_back(i+2);
        } else  {
            assert(i>0);
            i--;
            swap(a[i], a[i+1]);
            ans.push_back(i+1);
            if(i>0)
                i--;
        }

        while(i+1<n && a[i]<a[i+1])
            i++;

        op=!op;
    }
    cout<<ans.size()<<endl;
    for(int i : ans)
        cout<<i<<" ";
    cout<<endl;
}

signed main() {
    cini(t);
    while(t--)
        solve();
}
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[33;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
	static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
	return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
	cout<<x;
	if(suc==1) cout<<'\n';
	else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
	for(int i=0;i<v.size();i++)
	print(v[i],i==(int)(v.size())-1?suc:2);
}
void solve()
{
    int n;
    cin>>n;
    vi p(n);
    vi pos(n);
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
        p[i]--;
        pos[p[i]]=i;
    }
    if(n==4&&p[0]==3&&p[1]==2&&p[2]==1&&p[3]==0)
    {
        print(6);
        cout<<"1 2 3 2 1 2\n";
        return;
    }
    if(n==4&&p[0]==2&&p[1]==3&&p[2]==0&&p[3]==1)
    {
        print(6);
        cout<<"1 2 1 2 3 2\n";
        return;
    }
    //dbg(p);
    vi ans;
    auto change=[&](int x){
        assert(x%2==ans.size()%2&&x<n-1);
        ans.push_back(x+1);
        pos[p[x+1]]=x;
        pos[p[x]]=x+1;
        swap(p[x],p[x+1]);
    };
    auto waf=[&](){
        for(int i=0;i<n-1;i++)
        {
            if(i%2==0&&p[i]&&p[i+1])
            {
                change(i);
                break;
            }
        }
    };
    while(pos[0]!=0)
    {
        int tar=pos[0]-1;
        if(tar%2!=ans.size()%2)
            waf();
        change(tar);
    }
    auto cwp=[&](int x){
        assert(x);
        if(x%2==ans.size()%2) change(x);
        else{
            change(x-1);
            change(x);
            change(x-1);
            change(x);
            change(x-1);
        }
    };
    for(int i=1;i<n;i++)
    {
        //dbg(p);
        while(pos[i]!=i)
        {
            int tar;
            if(pos[i]>i) tar=pos[i]-1;
            else tar=pos[i];
            //dbg(tar);
            if(tar%2!=ans.size()%2)
            {
                if(abs(tar-i)<=1) cwp(tar);
                else {
                    for(int j=min(i,tar);j<=max(i,tar);j++)
                    {
                        if(j%2==ans.size()%2)
                        {
                            change(j);
                            break;
                        }
                    }
                }
            }
            else change(tar);
        }
    }
    print(ans.size());
    print(ans);
    //dbg(n,ans.size());
    assert(ans.size()<=n*n);
}
int main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--) solve();
}

// 1 3 2
// 3 1 2
// 3 2 1
// 2 3 1
// 2 1 3
// 1 2 3
