//#undef DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll llinf = (1ll<<61)-1;
#define sz(a) int(a.size())
#define all(x) begin(x), end(x)
#ifdef DEBUG
const int DEBUG_END = 26;
#define DOS cout
#include <debug.h>
#else
#define bug(args...) void()
#define cbug(a, args...)
#endif
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define fi first
#define se second
const int inf = 1000000007;
int TC = 1, CN;

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    //cin >> TC;// inputAll + resetAll -> solution
    auto kase = [&]()->void {
        string s;
        cin >> s;
        int o = 0, cnt[3] = {0};
        for (auto &i : s) {
            int x = (i-'0')%3;
            ++cnt[x];
            o += x;
        }
        o %= 3;
        cout << (o==0 ? 0 : (cnt[o] and sz(s)>1 ? 1 : (cnt[o^1^2] >= 2 and sz(s)>2 ? 2 : -1))) << '\n';
    };
    while (CN++!=TC) kase();
}

#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<regex>
using namespace std;
#define int long long
const int mod=1e9+7;
signed main(){
	int t,n,p[500];
	cin>>t;
	while(cin>>n){
		for(int i=0;i<n;i++){
			cin>>p[i];
			p[i]--;
		}
		if(n==2){
			if(p[0]==0)
				cout<<0<<endl;
			else
				cout<<1<<endl<<1<<endl;
			continue;
		}
		bool e=1;
		vector<int>ans;
		for(int i=n-1;i>=5;i--){
			int pos=-1;
			for(int j=0;j<n;j++){
				if(p[j]==i){
					pos=j;
					break;
				}
			}
			if(pos<i){
				if(pos%2==0&&!e){
					if(pos!=2){
						swap(p[1],p[2]);
						ans.push_back(1);
						e=!e;
					}else{
						swap(p[3],p[4]);
						ans.push_back(3);
						e=!e;
					}
				}else if(pos%2==1&&e){
					if(pos!=1){
						swap(p[0],p[1]);
						ans.push_back(0);
						e=!e;
					}else{
						swap(p[2],p[3]);
						ans.push_back(2);
						e=!e;
					}
				}
				for(int j=pos;j<i;j++){
					swap(p[j],p[j+1]);
					ans.push_back(j);
					e=!e;
				}
			}
		}
		if(n>=5){
			while(!(p[2]==4||p[3]==4||p[4]==4)){
				if(e){
					swap(p[0],p[1]);
					ans.push_back(0);
					e=!e;
				}else{
					swap(p[1],p[2]);
					ans.push_back(1);
					e=!e;
				}
			}
			while(!(p[4]==4)){
				if(e){
					swap(p[2],p[3]);
					ans.push_back(2);
					e=!e;
				}else{
					swap(p[3],p[4]);
					ans.push_back(3);
					e=!e;
				}
			}
		}
		if(n>=4){
			while(!(p[1]==3||p[2]==3||p[3]==3)){
				if(e){
					swap(p[0],p[1]);
					ans.push_back(0);
					e=!e;
				}else{
					swap(p[1],p[2]);
					ans.push_back(1);
					e=!e;
				}
			}
			while(!(p[3]==3)){
				if(e){
					swap(p[2],p[3]);
					ans.push_back(2);
					e=!e;
				}else{
					swap(p[1],p[2]);
					ans.push_back(1);
					e=!e;
				}
			}
		}
		if(n>=3){
			while(!(p[0]==0&&p[1]==1&&p[2]==2)){
				if(e){
					swap(p[0],p[1]);
					ans.push_back(0);
					e=!e;
				}else{
					swap(p[1],p[2]);
					ans.push_back(1);
					e=!e;
				}
			}
		}
		cout<<ans.size()<<endl;
		for(int i=0;i<ans.size();i++)
			cout<<ans[i]+1<<(i+1==ans.size()?'\n':' ');
	}
}