#pragma GCC optimize("Ofast,unroll-loops")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef int ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#ifdef SINA
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; }
template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); }
#define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1); cout.flush();
#else
#define dbg(...) 0
#define dbg2(x, j, n) 0
#endif
#define SZ(x) ((ll)((x).size()))
#define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout);
#define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i];
#define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n');
#define kill(x) return cout<< (x) << endl, 0
#define cl const ll
#define fr first
#define sc second
#define lc (v << 1)
#define rc (lc | 1)
#define mid ((l + r) >> 1)
#define All(x) (x).begin(), (x).end()

cl inf = sizeof(ll) == 4 ? (1e9 + 10) : (3e18), mod = 1e9 + 7, MOD = 998244353;

template <class A,class B> ostream& operator << (ostream& out,const pair<A,B>&a){return out<<'('<<a.first<<", "<<a.second<<')';}
template <class A> ostream& operator << (ostream& out, const vector<A> &a) {
	out<< '['; for (int i = -1; ++i < int(a.size());) out<< a[i] << (i + 1 < int(a.size()) ? ", " : ""); return out<<']'; }
template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>;

cl N = 5e2 + 7;

ll a [N], b [N], n;
vector <ll> ans;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

bool check () {
	for (ll i = 1; i < n; i++) if (a[i] > a[i + 1]) return false;
	return true;
}

void solve () {

	cin>> n;
	input(1, n, b);

	do {
	
	for (ll i = 1; i <= n; i++) a[i] = b[i];
	
	ans.clear();
	// bool f [2]; f[0] = f[1] = true;
	for (ll o = 1; ; o = 1 - o) {
		bool fnd = false;

		for (ll i = 2 - o; i < n; i += 2) if (a[i] > a[i + 1]) {
			swap(a[i], a[i + 1]);
			ans.push_back(i);
			// dbg(i, a[i]);
			fnd = true;
			break;
		}

		if (!fnd) {
			if (check()) break;
			
			ll x = rng() % n;

			if (!x) x++;

			if ((x & 1) != o) {
				if (x > 1) x--;
				else x++;
			}

			swap(a[x], a[x + 1]);
			ans.push_back(x);
		}
	}

	} while (SZ(ans) > n * n);
	// dbg(ans);
	cout<< SZ(ans) << '\n';
	output(0, SZ(ans), ans, 1);
}

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

	ll tst;
	for (cin>> tst; tst--;) solve();

	cerr<< "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

	return 0;
}
/*
1
4
1 4 2 3

1 4 2 3
1 4 3 2
1 3 4 2
1 3 2 4
1 2 3 4


1
4
1 4 3 2

1 4 3 2
1 4 2 3
1 2 4 3
1 2 3 4

*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int X; scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
#define loop(I, A, B) for (int I = (A); I <= (B); ++I)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)1e9+7;
const int SIZE = 2e5+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int p[100009];
int pp[100009];

int main(){
    CASET{
        DRI(n);
        REP(i,n){
            RI(p[i]);
            pp[i]=p[i];
        }
        if(n==2){
            if(p[0]==1)puts("0");
            else printf("1\n1\n");
            continue;
        }
        vector<int> ans;
        REP(i,n-3){//try and find value 0...i-1 positions are all ok. Avoid flipping <i i+1;
            while(1){
                int sp=0;//move this to position i
                REP(j,n){
                    if(p[j]==i+1){
                        sp=j;
                        break;
                    }
                }
                if(sp==i)break;//good position
                if(sp%2!=SZ(ans)%2){//bingo!
                    while(sp>i){
                        sp--;
                        swap(p[sp],p[sp+1]);
                        ans.PB(sp);
                    }
                    break;
                }
                else{//avoid if possible
                    int nx = i;
                    if(nx%2!= SZ(ans)%2){
                        nx++;
                    }
                    for(int j=nx;j<n-1;j+=2){
                        if(j!=sp&&j+1!=sp){
                            nx=j;break;
                        }
                    }
                    swap(p[nx],p[nx+1]);
                    ans.PB(nx);
                }
            }
        }
        REP(it,10){
            bool good = 1;
            REPP(i,n-3,n){
                good&=p[i]==i+1;
            }
            if(good)break;
            int x = n-2;
            if(x%2!=SZ(ans)%2){
                x--;
            }
            swap(p[x],p[x+1]);
            ans.PB(x);
        }
        /*for(int i:ans){
            swap(pp[i],pp[i+1]);
            REP(j,n){
                printf("%d ",pp[j]);
            }puts("");
        }*/
        printf("%d\n",SZ(ans));
        REP(i,SZ(ans)){
            if(i)printf(" ");
            printf("%d",ans[i]+1);
        }puts("");case_n++;
    }
}
