#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native")

#define ll long long
#define int ll
#define ull unsigned ll
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(vector<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 826
#endif
template<typename T> void print(T && x) {cout << x << "\n";}
template<typename T, typename... S> void print(T && x, S&&... y) {cout << x << ' ';print(y...);}

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
const int maxn=505;

//i_am_noob
#define wiwihorz  
int n,a[maxn];
vector<int> res;

void op(int x){
    if((x+sz(res))&1){
        bug(x,sz(res));
    }
    if(sz(res)==60604) bug(x);
    assert((x+1+sz(res))&1);
    res.pb(x+1);
    swap(a[x],a[x+1]);
}

void report(){
    print(sz(res));
    for(auto i: res) print0(i);
    cout << "\n";
}

void orzck(){
    res.clear();
    cin >> n;
    rep(n) cin >> a[i];
    rep(n) a[i]--;
    if(n<=3){
        while(!is_sorted(a,a+n)){
            if(sz(res)&1) op(1);
            else op(0);
        }
        report();
        return;
    }
    rep3(i,n-1,4){
        int pos;
        rep1(j,n) if(a[j]==i) pos=j;
        if((pos+sz(res))&1){
            if(sz(res)&1) op(pos==2?3:1);
            else op(pos==1?2:0);
        }
        rep2(j,pos,i) op(j);
    }
    bug(sz(res));
    rep(n) bug(a[i]);
    int pos;
    if(sz(res)&1) op(1);
    rep(4) if(a[i]==3) pos=i;
    if((pos+1+sz(res))&1){
        rep2(i,pos,3) op(i);
    }
    else if(pos<3){
        op(2);
        rep2(i,pos,3) op(i);
    }
    rep(n) bug(a[i]);
    while(!is_sorted(a,a+n)){
        if(sz(res)&1) op(1);
        else op(0);
    }
    assert(is_sorted(a,a+n));
    report();
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    #ifdef i_am_noob
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    freopen("output2.txt","w",stderr);
    #endif
    cout << fixed << setprecision(15);
    int t;
    #ifdef wiwihorz
    cin >> t;
    #else
    t=1;
    #endif
    while(t--) orzck();
    return 0;
}
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 2e5 + 10;

int a[N], res[N], pos[N];

void Swap(int p, int &idx) {
	swap(pos[a[p]], pos[a[p + 1]]);
	swap(a[p], a[p + 1]);
	res[idx++] = p;
}

void solve() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		pos[a[i]] = i;
	}
	int idx = 1;
	for(int i = n; i >= 1; i--) {
		if(a[i] == i) continue;
		while(idx % 2 != pos[i] % 2) {
			if(idx & 1) Swap(1, idx);
			else Swap(2, idx);
		}
		while(pos[i] != i) {
			Swap(pos[i], idx);
		}
	}
	printf("%d\n", idx - 1);
	for(int i = 1; i < idx; i++) {
		printf("%d ", res[i]);
	}
	puts("");
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE

    int t; cin >> t; while(t--)
    solve();
    return 0;
}
