#pragma GCC optimize(2)
//#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#define rush()      int T; while(cin>>T) while(T--)
#define ms(a,b)     memset(a,b,sizeof a)
#define lowbit(x)   ((x)&(-x))
#define inf         0x7f7f7f7fll
#define eps         1e-11
#define sd(a)       scanf("%d",&a)
#define sll(a)      scanf("%lld",&a)
#define sll2(a,b)   scanf("%lld%lld",&a,&b)
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sdd(a,b)    scanf("%d%d",&a,&b)
#define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sf(a)       scanf("%lf",&a)
//#define sc(a)       scanf("%c\n",&a)
#define ss(a)       scanf("%s",a)
#define pd(a)       printf("%d\n",a)
#define pdd(a,b)    printf("%d %d\n",a,b)
#define pddd(a,b,c) printf("%d %d %d\n",a,b,c)
#define pll(a)      printf("%lld\n",a)
#define pf(a)       printf("%.1lf\n",a)
#define pc(a)       printf("%c",a)
#define ps(a)       printf("%s\n",a)
#define rep(i,a,b)  for(int i=(a);i<=(b);i++)
#define forn(i,a,b,x)  for(int i=(a);i<=(b);i+=(x))
#define per(i,a,b)  for(int i=(b);i>=(a);i--)
#define pb(a)       push_back(a)
#define mp(a,b)     make_pair(a,b)
#define debug(a)    cout<<#a<<" : "<<a<<" "<<" ; "
#define dbg(a)      cout<<#a<<" : "<<a<<endl
#define show(a,b)   cout<<a<<" :\t"<<b<<"\t*"<<endl
#define IOS         ios::sync_with_stdio(0); cin.tie(0)
#define PAUSE       system("pause")
#define all(x)      x.begin(),x.end()
//#define print(a)    cout<<a<<endl;continue;
#define fr          first
#define sc          second
#define ceils(a,b)  ((a-1ll+b)/(b))
#define floors(a,b) floor(double(a)/double(b))
using namespace std;
//inline void swap(int &x,int &y){x^=y^=x^=y;}
typedef long long ll;
//using ui=unsigned int;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const double pi=acos(-1.0);
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const int limit=5e5;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}

void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x<10) putchar(x+'0');
	else write(x/10),putchar(x%10+'0');
}

void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}

ll mod=2147483648;
const int N=3e5+5;
 
    int n, m, _;
    int i, j, k;
    int a[N];
    int pos[N];
    vector<int> ans;

signed main()
{
    //IOS;
    rush(){
        sd(n);
        rep(i, 1, n) sd(a[i]), pos[a[i]] = i;
        int opt = 1;
        rep(i, 1, n){
            if(i == pos[i]) continue;
            if((pos[i] - 1) % 2 != opt){
                if(pos[i] - 2 >= i){
                    ans.pb(pos[i] - 2);
                    int x = pos[i] - 2, y = pos[i] - 1;
                    swap(pos[a[x]], pos[a[y]]);
                    swap(a[x], a[y]);
                    opt ^= 1;
                }
                else if(pos[i] == i + 1){
                    ans.pb(i - 1);
                    ans.pb(i);
                    ans.pb(i - 1);
                    ans.pb(i);
                    ans.pb(i - 1);
                    //ans.pb(i);
                    opt ^= 1;
                    int x = pos[i], y = pos[i] - 1;
                    swap(pos[a[x]], pos[a[y]]);
                    swap(a[x], a[y]);
                    continue;
                }
            }
            for(int j = pos[i] - 1; j >= i; j--){
                ans.pb(j);
                int x = j, y = j + 1;
                swap(pos[a[x]], pos[a[y]]);
                swap(a[x], a[y]);
                opt ^= 1;
            }
        }
        pd(ans.size());
        for(auto it : ans) printf("%d ", it);
        puts("");
        ans.clear();
    }
    //PAUSE;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto &a:x)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define f first
#define s second
#define nl '\n'
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int n, turn, t;
int a[501];
int pos[501];
vi ans;

void swap(int i){
	swap(a[i], a[i+1]);
	swap(pos[a[i]], pos[a[i+1]]);
	ans.pb(i);
	turn++;
}

void solve3(){
	while(!(a[1]==1 && a[2]==2 && a[3]==3)){
		if(turn&1) swap(1);
		else swap(2);
	}
}

void solve4(){
	while(a[4]!=4){
		if(turn&1){
			if(a[1]==4) swap(1);
			else swap(3);
		}
		else swap(2);
	}
	solve3();
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	// freopen("input.txt", "r", stdin);

	cin >> t;
	while(t--){
		turn=1;
		ans.clear();
		cin >> n;
		rep(i, 1, n){
			cin >> a[i];
			pos[a[i]]=i;
		}
	
		if(n==2){
			if(a[1]==1) cout << "0";
			else cout << "1\n1";
			cout << nl;
			continue;
		}
		if(n==3) solve3();
		else if(n==4) solve4();
		else{
			turn=1;
			for(int i=n; i>=5; i--) {
				if(pos[i]==i) continue;
				if(turn%2!=pos[i]%2){
					if(pos[i]-3>=1) swap(pos[i]-3);
					else swap(pos[i]+1);
				}
				while(pos[i]!=i){
					swap(pos[i]);
				}
			}
			solve4();
		}
	
		cout << sz(ans) << nl;
		trav(k, ans) cout << k << " ";
		cout << nl;
	}
}
