#include <bits/stdc++.h>

using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

class rep {
    struct Iter {
        usize itr;
        constexpr Iter(const usize pos) noexcept : itr(pos) {}
        constexpr void operator++() noexcept { ++itr; }
        constexpr bool operator!=(const Iter& other) const noexcept { return itr != other.itr; }
        constexpr usize operator*() const noexcept { return itr; }
    };
    const Iter first, last;

  public:
    explicit constexpr rep(const usize first, const usize last) noexcept : first(first), last(std::max(first, last)) {}
    constexpr Iter begin() const noexcept { return first; }
    constexpr Iter end() const noexcept { return last; }
};

template <class T> using Vec = std::vector<T>;

void main_() {
    usize N;
    std::cin >> N;
    Vec<usize> P(N);
    for (auto& x : P) {
        std::cin >> x;
        x -= 1;
    }
    if (std::is_sorted(P.begin(), P.end())) {
        std::cout << 0 << '\n';
        std::cout << '\n';
        return;
    }
    if (N == 2) {
        std::cout << 1 << '\n';
        std::cout << 1 << '\n';
        return;
    }
    Vec<usize> ans;
    ans.reserve(N * N);
    const auto add = [&](const usize i) {
        assert(ans.size() % 2 == i % 2);
        assert(i + 1 < N);
        ans.push_back(i);
        std::swap(P[i], P[i + 1]);
    };
    for (const auto i : rep(0, N - 3)) {
        usize k = 0;
        while (P[k] != i) {
            k += 1;
        }
        if (k == i) {
            continue;
        }
        std::cerr << k << std::endl;
        if (ans.size() % 2 != (k - 1) % 2) {
            if (k == N - 1) {
                add(k - 2);
            } else {
                add(k);
                add(k - 1);
                k += 1;
            }
        }
        while (k != i) {
            add(k - 1);
            k -= 1;
        }
    }
    std::array<usize, 2> idx;
    idx[0] = N - 3;
    idx[1] = N - 2;
    if (idx[0] % 2 != ans.size() % 2) {
        std::swap(idx[0], idx[1]);
    }
    while (!std::is_sorted(P.begin(), P.end())) {
        add(idx[0]);
        std::swap(idx[0], idx[1]);
    }
    assert(std::is_sorted(P.begin(), P.end()));
    assert(ans.size() <= N * N);
    std::cout << ans.size() << '\n';
    for (const auto i : rep(0, ans.size())) {
        if (i > 0) {
            std::cout << ' ';
        }
        std::cout << ans[i] + 1;
        assert(ans[i] % 2 == i % 2);
    }
    std::cout << '\n';
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    usize cases;
    std::cin >> cases;
    while (cases--) main_();
    return 0;
}

#include<bits/stdc++.h>
#define LL long long
#define DB double
#define pb push_back
#define mkp make_pair
#define LB lower_bound
#define UB upper_bound
#define rint register int
#define MS(x,y) memset(x,y,sizeof(x))
#define rep(i,a,b) for(rint i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(rint i=a,i##end=b;i>=i##end;--i)
#define cms printf("%.2lf\n",(&o2-&o1)/1024.0/1024)
using namespace std;bool o1;
char IO;
inline int Rd(){
	int _s_=0;
	bool _f_=0;
	while(!isdigit(IO=getchar()))
		IO=='-'&&(_f_=1);
	do _s_=(_s_<<1)+(_s_<<3)+(IO^48);
	while(isdigit(IO=getchar()));
	return _f_?-_s_:_s_;
}
int n,p,o,ans[250004],a[505],t,tt;
void DO(int x){
	ans[++o]=x;
	swap(a[x],a[x+1]);
	p^=1;
}
bool o2;int main(){
	rep(T,1,Rd()){
		n=Rd();
		rep(i,1,n)
			a[i]=Rd();
		if(n==2){
			if(a[1]==1)
				printf("0\n\n");
			else printf("1\n1\n");
			continue;
		}
		p=1;
		o=0;
		rep(i,1,n-2){
			if(a[i]==i)
				continue;
			rep(j,i+1,n)
				if(a[j]==i)
					t=j;
			if(t%2==p){
				if(t>i+1)
					DO(t-2);
				else {
					DO(t),DO(t-1);
					t++;
				}
			}
			drep(j,t-1,i)
				DO(j);
		}
		if(a[n]!=n){
			if(n%2==p){
				DO(n-2);
				DO(n-1);
				DO(n-2);
				DO(n-1);
				DO(n-2);
			}
			else DO(n-1);
		}
		printf("%d\n",o);
		rep(i,1,o)
			printf("%d ",ans[i]);
		puts("");
	}
	return 0;
}