#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    ll ans=LLONG_MAX;
    for(ll bit=0; bit<(1<<n); bit++){
        ll tmp_ans=0;
        vector<ll> v;
        ll tmp=0;
        for(int i=0; i<n; i++){
            tmp|=a[i];
            if(bit&(1<<i) || i==n-1){
                v.emplace_back(tmp);
                tmp=0;
            }
        }
        for(auto t : v){
            tmp_ans ^= t;
        }
        ans = min(ans, tmp_ans);
    }
    cout << ans << endl;
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define all(x) x.begin(),x.end()
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
    os << "[";
    for (ll i=0; i < v.size(); ++i) {
        os << v[i];
        if (i != v.size() - 1)
            os << ", ";
    }
    os << "]";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v){
    os << "{";
    for (auto it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}";
    return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v){
    os<<"{";
    for (auto it : v){
        os << it.first << " : "
           << it.second ;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}";
    return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v){
    os << "(";
    os << v.first << ", "
       << v.second << ")";
    return os;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        vector<ll> arr(n);
        REP(i,n){
            cin>>arr[i];
            arr[i]--;
        }
       // cout<<arr<<endl;
        if(n==2){
            if(arr[0]==0){
                cout<<0<<endl;
            }
            else{
                cout<<1<<endl;
                cout<<1<<endl;
            }
            continue;
        }
        ll turn=0;
        vector<ll> ans;
        for(ll elem=n-1;elem>2;elem--){
            ll pos;
            for(ll i=0;i<=elem;i++){
                if(arr[i]==elem){
                    pos=i;
                    break;
                }
            }
            if(pos==elem) continue;
            if((pos & 1)==turn){
                for(ll i=pos;i<elem;i++){
                    ans.pb(i);
                    swap(arr[i],arr[i+1]);
                    turn^=1;
                }
            }
            else{
                ll ideal=-1;
                for(ll j=0;j<elem;j++){
                    if((j & 1)==turn){
                        if(j+1!=pos){
                            ideal=j;
                            break;
                        }
                    }
                }
                if(ideal!=-1){
                    ans.pb(ideal);
                    swap(arr[ideal],arr[ideal+1]);
                    turn^=1;
                    for(ll i=pos;i<elem;i++){
                        ans.pb(i);
                        swap(arr[i],arr[i+1]);
                        turn^=1;
                    }
                }
                else{
                    ans.pb(pos-1);
                    swap(arr[pos-1],arr[pos]);
                    turn^=1;
                    ans.pb(pos);
                    swap(arr[pos],arr[pos+1]);
                    turn^=1;
                    for(ll i=pos-1;i<elem;i++){
                        ans.pb(i);
                        swap(arr[i],arr[i+1]);
                        turn^=1;
                    }
                }
            }
        }
       // cout<<arr<<endl;
       // cout<<turn<<endl;
        vector<ll> aux(arr.begin(),arr.begin()+3);
        vector<ll> tar{0,1,2};
        while(aux!=tar){
            if(turn & 1){
                ans.pb(1);
                swap(aux[1],aux[2]);
                turn^=1;
            }
            else{
                ans.pb(0);
                swap(aux[0],aux[1]);
                turn^=1;
            }
        }
        cout<<ans.size()<<endl;
        for(auto & x:ans){
            cout<<x+1<<" ";
        }
        cout<<endl;

    }

}
