#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];
int lst[1<<26];

vector<int> solve(vector<int> a) {
    vector<int> ans;
    int n = a.size();
    if(n == 1)
        return {0};

    for(int i=0; i<=25; i++)
        lst[1<<i] = -1;

    vector<int> x, y;
    for(int i=0; i<n; i++) {
        if(lst[a[i]] != -1) {
            x.pb(lst[a[i]]);
            y.pb(i);
            lst[a[i]] = -1;
        }
        else
            lst[a[i]] = i;
    }
    vector<int> rem;
    for(int i=0; i<=25; i++)
        if(lst[1<<i] != -1)
            rem.pb(lst[1<<i]);
    
    int m = rem.size();
    if(m == 1) {
        x.pb(rem[0]);
    }
    else {
        for(int i=0; i<m/2-1; i++)
            x.pb(rem[i]);
        x.pb(rem[m-1]);
        for(int i=m/2-1; i<m-1; i++)
            y.pb(rem[i]);
    }

    ans = x;
    for(auto idk : y)
        ans.pb(idk);

    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);

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

    }
    return 0;
}
#endif