#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define sc second

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e6 + 5;
const ll inf = 1e16;

bool taken[N];

vector<int> solve(vector<int> a) {
    vector<int> ans;
    int n = a.size();

    for(int i=0; i<n/2-1; i++)
        ans.pb(i);
    ans.pb(n-1);
    for(int i=n/2-1; i<n-1; i++)
        ans.pb(i);

    return ans;
}

#ifndef EVAL
int32_t main() {
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
    cin.tie(nullptr)->sync_with_stdio(0);

    int tt;
    cin >> tt;
    while(tt--) {
        vector<int> a;
        int n;
        cin >> n;
        for(int i=1; i<=n; i++) {
            int x;
            cin >> x;
            a.pb(x);
        }

        vector<int> res = solve(a);
        int pax = 0, sum = 0, s = (1 << n) - 1;
        for(auto x : res) {
            sum += (1 << x);
            pax++;
            if(sum >= s / 2.0)
                break;
        }

        assert(abs(pax-(n-pax)) <= 1);
        for(auto x : res)
            cout << x << ' ';
        cout << '\n';

    }
    return 0;
}
#endif