#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define ld long double
#define For(i,x,y) for(ll i = (ll)(x);i <= (ll)(y);++i)
#define FOr(i,x,y) for(ll i = (ll)(x);i >= (ll)(y);--i)
#define rep(i,x,y) for(ll i = (ll)(x);i < (ll)(y);++i)
#define fi first
#define se second
#define pa pair<ll,ll>
#define pb push_back
#define y1 y11111111111111
#define debug puts("@@@@@@@@@@@@@@@@@@@")
 
#define cpy(a,b) memcpy(a,b,sizeof(b))
inline ll read()
{
	ll x = 0,f = 1;char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x*10+ch-'0';ch = getchar();}
	return x*f;
}
 
void write(ll x)
{
	if(x < 0) putchar('-'), x= -x;
	if(x > 9)write(x/10);
	putchar(x%10+'0');
}
const ll N=200010;
ll n,a[N];
vector<ll>ans;
bool ok(){
	For(i,1,n-1)if(a[i]>a[i+1])return 0;
	return 1; 
}
void swp(ll i,ll j){
	swap(a[i],a[j]);
	ans.pb(i);
}
int main(){
	ll T=read();
	for(;T--;){
		n=read();	ans.clear();
		For(i,1,n)a[i]=read();
		for(;;){
			if (ok())break; 
			bool fl=0;
			For(i,1,n-1)if(i&1){
				if (a[i]>a[i+1]){
					swp(i,i+1);
					fl=1;
					break;
				}
			}
			if(!fl){
				if(n&1)	swp(n-2,n-1);
				else	swp(n-1,n);
			}
			if (ok())break;
			fl=0;
			For(i,1,n-1)if(!(i&1)){
				if (a[i]>a[i+1]){
					swp(i,i+1);
					fl=1;
					break;
				}
			}
			if(!fl){
				if(n&1) swp(n-1,n);
				else	swp(n-2,n-1);
			}
		}
		cout<<ans.size()<<endl;;
		rep(i,0,ans.size())write(ans[i]),putchar(' ');puts(""); 
	}
}
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX>>2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x))
#define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
#define ms multiset
#define is insert
#define um unordered_map
using namespace std;
void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}}
ll fa[MAX];
ll power(ll p,ll q){
    ll res=1;
    p%=mod;
    while(q){
        if (q&1)
            res=(res*p)%mod;
        q>>=1;
        p=(p*p)%mod;
    }
    return res;
}
ll fact(ll n){
    if (n<=1)
        return fa[n]=1;
    if (fa[n])
        return fa[n];
    return fa[n]=(n*fact(n-1))%mod;
}
ll ncr(ll n,ll r){
    if (!r)
        return 1;
    return (((fact(n)*power(fact(n-r),mod-2))%mod)*power(fact(r),mod-2))%mod;
}
void solve(){
    ll i,j,sum,ans=inf,count;
    string s;
    cin>>s;
    f(j,0,1<<s.length(),1){
        sum=count=0;
        f(i,0,s.length(),1)
            if (!((1<<i)&j))
                sum+=s[i]-'0';
            else
                count++;
        if (!(sum%3))
            ans=min(ans,count);
    }
    cout<<(ans==s.length()?-1:ans)<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}