#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define double long double
//#define DB
#ifdef DB
#define el cerr << "\n";
    #define db(...) cerr << " [" << #__VA_ARGS__ << " : " << __VA_ARGS__ << "] ";
#else
#define el
#define db(...)
#endif // DB
const int N = 505;
int n;
int p[N];
int sz;
int moves[N * N];
int curPos[N];

void doSwap(int i) {
    swap(p[i], p[i + 1]);
    curPos[p[i]] = i;
    curPos[p[i + 1]] = i + 1;
    moves[sz] = i;
    ++sz;
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
        curPos[p[i]] = i;
    }
    sz = 0;
    for (int i = 1; i <= n; ++i) {
        if (p[i] == i) continue;
        int j = curPos[i];
        if (j % 2 != sz % 2) {
//            if (j < n - 2) {
//                doSwap(j + 2);
//            } else
            if (i < j - 1) {
                doSwap(j - 2);
            } else { // A i j
                doSwap(i - 1); doSwap(i);
                doSwap(i - 1); doSwap(i);
                doSwap(i - 1);
                continue;
            }
        }
        for (int k = j - 1; k >= i; --k) {
            doSwap(k);
        }
    }
}

int main() {
//    freopen("C:\\Users\\T\\CLionProjects\\cp-chemthan\\atcoder\\regular121\\C.in", "r", stdin);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
        cout << sz << "\n";
        if (sz) {
            for (int i = 0; i < sz; ++i) {
                cout << moves[i] << " ";
            }
            cout << "\n";
        }
    }
    return 0;
}

/*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\n'
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\n';

using namespace std;
template<class T>void show(vector<T> &a) {cerr << "[ "; for (int ij = 0; ij < (int)a.size(); ij++) {cerr << a[ij] << " ";} cerr << "]\n";}
template<class T>void show(T a) {cerr << a << endl;}
template<typename... T>void show(T... args) {((cerr << args << ' '), ...); cerr << endl;}
template<class T>void read(vector<T> &a) {for (auto &x : a) {cin >> x;}}
template<class T> void read(T &a) {cin >> a;}

void solve() {
	int i, j;
	int n;

	read(n);

	vector<int> a(n);

	read(a);

	vector<int> ans;

	int f=0;
	while(!is_sorted(a.begin(),a.end())){
		bool b=1;
		for (int j = 0; j < n-1; ++j)
		{
			if(a[j]>a[j+1] && j%2==f){
				swap(a[j],a[j+1]);
				ans.push_back(j+1);
				f^=1;
				b=0;
			}
		}
		if(b){
			ans.push_back(f+1);
			swap(a[f],a[f+1]);
			f^=1;
		}
	}

	cout << ans.size() << endl;

	for(auto &x:ans){
		cout << x << ' ';
	}
	cout << endl;

}


int32_t main(int32_t argc, char *argv[]) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int T = 1;
	cin >> T;
	while (T--) {
		solve();
	}
	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
}