#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
const int N=3e5+5;
const int M=1e5+5;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-8;
const long double pi=acos(-1.0L);
#define ls (i<<1)
#define rs (i<<1|1)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
LL read()
{
    LL x=0,t=1;
    char ch;
    while((ch=getchar())<'0'||ch>'9') if(ch=='-') t=-1;
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+ch-'0'; ch=getchar(); }
    return x*t;
}
int a[N],ans[N];
int main()
{
    int T=read();
    while(T--)
    {
        //并不需要考虑去将每一个数字归位，而是可以直接考虑减少逆序对(交换相邻的逆序数字)
        int n=read(),tot=0;
        for(int i=1;i<=n;i++) a[i]=read();
        for(int k=0;;k^=1){
            int flag=0;
            for(int i=1;i<n;i++)
                if(a[i]>a[i+1]) flag=1;
            if(!flag) break;
            int i;
            for(i=k+1;i<n&&a[i]<a[i+1];i+=2);
            if(i>=n) i-=2;
            ans[++tot]=i;
            swap(a[i],a[i+1]);
        }
        printf("%d\n",tot);
        for(int i=1;i<=tot;i++) printf("%d%c",ans[i],i==tot?'\n':' ');
    }

    return 0;
}

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

#define   fi(a,b) for(int i=a;i<b;i++)
#define   fj(a,b) for(int j=a;j<b;j++)
#define   ff first
#define   ss second
#define   ll long long
#define   ld long double
#define   ull unsigned long long
#define   bp(x) __builtin_popcount(x)
#define   pr(x) for(auto it: x) cout<<it<<" "; cout<<endl;
#define   getMax(x) max_element(x.begin(),x.end())
#define   getMin(x) min_element(x.begin(),x.end())
#define   endl "\n"
typedef   vector<int> vi;
typedef   vector< pair<int, int> > vii;
typedef   vector<long long> vl;
typedef   pair<int, int> pii;
typedef   pair<ll, ll> pll;
typedef   vector< pair<ll, ll> > vll;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// auto dist = uniform_int_distribution<int>(l, r);
// int dx[] = {1, 0, -1, 0};
// int dy[] = {0, 1, 0, -1};
// int dx[] = { -1, 0, 1, 1, 1, 0, -1, -1};
// int dy[] = { -1, -1, -1, 0, 1, 1, 1, 0};


void omae_wa_mou_shindeiru(int tc) {
	ll n;
	cin >> n;
	vl p(n + 1), f(n), ans;
	fi(1, n + 1) {
		ll temp;
		cin >> temp;
		p[i] = temp;
	}
	vl temp = p;
	sort(temp.begin(), temp.end());
	set<int>odd, even;
	fi(1, n) {
		if (p[i] > p[i + 1]) {
			if (i % 2)
				odd.insert(i);
			else
				even.insert(i);
		}
	}

	fi(1, n * n + 1) {
		if (p == temp) {
			break;
		}
		if (i % 2) {
			int kk;
			if (odd.size() == 0) {
				kk = n - 1 - (n % 2);
			}
			else {
				kk = *odd.begin();
				odd.erase(odd.begin());
			}
			swap(p[kk], p[kk + 1]);
			ans.push_back(kk);
			if (even.find(kk + 1) != even.end()) {
				even.erase(kk + 1);
			}
			if (even.find(kk - 1) != even.end()) {
				even.erase(kk - 1);
			}
			if (kk + 2 <= n) {
				if (p[kk + 1] > p[kk + 2]) {
					even.insert(kk + 1);
				}
			}
			if (kk - 1 >= 1) {
				if (p[kk - 1] > p[kk]) even.insert(kk - 1);
			}
		}
		else {
			int kk;
			if (even.size() == 0) {
				kk = n - 1 - (n + 1) % 2;
			}
			else {
				kk = *even.begin();
				even.erase(even.begin());
			}
			swap(p[kk], p[kk + 1]);
			ans.push_back(kk);
			if (odd.find(kk + 1) != odd.end()) {
				odd.erase(kk + 1);
			}
			if (odd.find(kk - 1) != odd.end()) {
				odd.erase(kk - 1);
			}
			if (kk + 2 <= n) {
				if (p[kk + 1] > p[kk + 2]) odd.insert(kk + 1);
			}
			if (kk - 1 >= 1) {
				if (p[kk - 1] > p[kk]) odd.insert(kk - 1);
			}
		}
		// pr(p);
	}
	cout << ans.size() << endl;
	pr(ans);

}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int tc = 1;
	cin >> tc;
	fi(1, tc + 1) {
		omae_wa_mou_shindeiru(i);
	}
}
