#include <bits/stdc++.h>
using namespace std;
int T , n , a[550] , pl[550] , minn[2] , noww , it , flag , ans[300000] , tot , p[550];
void build( int l )
{
	for(int i = 1 ; i <= n ; i++ ) pl[a[i]] = i;
	minn[1] = minn[0] = 1e9;
	for(int i = l ; i <= n ; i++ ) minn[i & 1] = min(minn[i & 1] , a[i]);
//	for(int i = l ; i <= n ; i++ ) 
//		if(a[i] == 297) cerr << minn[i & 1] << endl; 
	return ;
}
void print( int a )
{
	int qwq = a / 10;
	if(qwq) print(qwq);
	putchar(a - (qwq << 1) - (qwq << 3) + '0');
	return ;
}
void run( int pl )
{
	ans[++tot] = pl - 2; swap(a[pl - 2] , a[pl - 1]);
	ans[++tot] = pl - 1; swap(a[pl - 1] , a[pl]);
	ans[++tot] = pl - 2; swap(a[pl - 2] , a[pl - 1]);
	ans[++tot] = pl - 1; swap(a[pl - 1] , a[pl]);
}
void walk( int pl )
{
	ans[++tot] = pl - 2; swap(a[pl - 2] , a[pl - 1]);
	ans[++tot] = pl - 1; swap(a[pl - 1] , a[pl]);
	ans[++tot] = pl - 2; swap(a[pl - 2] , a[pl - 1]);
	ans[++tot] = pl - 1; swap(a[pl - 1] , a[pl]);
	ans[++tot] = pl - 2; swap(a[pl - 2] , a[pl - 1]);
}
int main()
{
//	freopen("1.in" , "r" , stdin);
//	freopen("1.out" , "w" , stdout);
	scanf("%d" , &T);
	while(T--)
	{
//		cerr << 11111;
		scanf("%d" , &n); noww = tot = flag = 0; it = 1;
		for(int i = 1 ; i <= n ; i++ ) scanf("%d" , &a[i]) , p[i] = 1 , flag |= (a[i] != i);
		if(!flag)
		{
//			printf("yes\n");
			if(a[2] == 2) printf("0\n\n");
			continue;
		}
		if(n == 2)
		{
//			printf("yes\n");
			if(a[2] == 2) printf("0\n\n");
			else printf("1\n1\n");
			continue;
		}
		if(a[1] == 1) it = 2 , p[1] = 0;
		build(it);
		while(it <= n)
		{
			int u = minn[noww] , d = 0;
			if(u > 500) u = a[n - (noww ^ (n & 1))];
			p[u] = 0;
			for(int i = 1 ; i < u ; i++ ) d += p[i]; 
			for(int i = pl[u] - 1 ; i >= u - d ; i-- ) 
				ans[++tot] = i , swap(a[i] , a[i + 1]) , noww ^= 1;
			it++;
			build(it);
//			for(int i = 1 ; i <= n ; i++ ) cerr << a[i] << ' '; cerr << endl;
		}
		if(a[n] != n)
		{
//			cerr << 111111;
			int pl = n , u = a[n];
			while(pl - u >= 2) run(pl) , pl -= 2;
			if(pl - u == 1) walk(pl);
//			if(pl - u == 1) cerr << a[n] << ' ' << "walk\n";
//			else cerr << a[n] << ' ' << "run\n";
		}
//		for(int i = 1 ; i <= n ; i++ ) cerr << a[i] << ' '; cerr << endl;
		print(tot); printf("\n");
		for(int i = 1 ; i <= tot ; i++ ) print(ans[i]) , putchar(' '); printf("\n");
//		while(1);
//		flag = (tot > n * n);
//		for(int i = 1 ; i <= n ; i++ ) flag |= (a[i] != i);
//		for(int i = 1 ; i <= tot ; i++ ) flag |= (ans[i] == 0);
//		if(flag) printf("no\n");
//		else printf("yes\n");
	}
	return 0;
}
/*
1
4
1 2 3 4 
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, p[555], at;
vector<ll> ans;

void sp(ll k){
    ans.push_back(k);
    ll tmp = p[k];
    p[k] = p[k + 1];
    p[k + 1] = tmp;
}

void lst4(){
    if(p[4] == 4)return;
    if(p[3] == 4){
        if(ans.size() % 2 == 0){
            sp(3);
        }else{
            sp(2);
            sp(3);
            sp(2);
            sp(3);
        }
        return;
    }
    if(p[2] == 4){
        if(ans.size() % 2 == 1){
            sp(2);
            sp(3);
        }else{
            sp(3);
            sp(2);
            sp(3);
        }
        return;
    }
    if(p[1] == 4){
        if(ans.size() % 2 == 0){
            sp(1);
            sp(2);
            sp(3);
        }else{
            sp(2);
            sp(1);
            sp(2);
            sp(3);
        }
    }
}

void lst3(){
    while(p[1] != 1 || p[2] != 2){
        if(ans.size() % 2 == 0){
            sp(1);
        }else{
            sp(2);
        }
    }
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll T; cin >> T;
    while(T--){
        while(!ans.empty())ans.pop_back();

        cin >> n;
        rep(i, 1, n)cin >> p[i];

        if(n == 2){
            if(p[1] != 1)sp(1);
        }else{
            rrep(i, n, 5){
                if(p[i] == i)continue;

                rep(j, 1, i)if(p[j] == i)at = j;
                
                if(ans.size() % 2 == 1 && at % 2 == 1){
                    if(at == 3){
                        sp(4);
                    }else{
                        sp(2);
                    }
                }

                if(ans.size() % 2 == 0 && at % 2 == 0){
                    if(at == 2){
                        sp(3);
                    }else{
                        sp(1);
                    }
                }

                rep(j, at, i - 1){
                    sp(j);
                }
            }
            if(n >= 4)lst4();
            lst3();
        }

        print(ans.size())
        zep(j, 0, ans.size())cout << ans[j] << " "; cout << endl;
    }
    
    return 0;
}