#include <bits/stdc++.h>

using namespace std;

#define flush cout.flush

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pl = pair<ll, ll>;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-9;
const ld PI = acos(-1);

void solve() {
    ll n;
    cin >> n;
    vector<ll> p(n);
    for (ll &i : p)cin >> i;
    vector<ll> ans;
    ll oper = 1;
    ll cur = 1;
    bool ok = true;
    while (cur <= n) {
        ll i;
        for (i = 0; i < n; ++i) {
            if (p[i] == cur)break;
        }
        if (i + 1 == cur) {
            cur++;
            continue;
        }
        if (i % 2 == oper % 2) {
            ans.push_back(i);
            swap(p[i], p[i - 1]);
            oper++;
        } else {
            if (cur % 2 == oper % 2) {
                oper++;
                swap(p[cur], p[cur - 1]);
                ans.push_back(cur);
            } else {
                if (cur == n - 1) {
                    swap(p[cur - 2], p[cur - 1]);
                    ans.push_back(cur - 1);
                    swap(p[cur], p[cur - 1]);
                    ans.push_back(cur);
                    swap(p[cur - 2], p[cur - 1]);
                    ans.push_back(cur - 1);
                    oper += 3;
                    cur--;
                }
                oper++;
                swap(p[cur], p[cur + 1]);
                ans.push_back(cur + 1);
            }
        }
    }
    if (ans.size() > n * n || !is_sorted(p.begin(), p.end())) {
        cout << 1 / 0;
        return;
    }
    cout << ans.size() << "\n";
    for (auto x : ans)cout << x << " ";
    cout << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while (t--)solve();
    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;
}
