#include <bits/stdc++.h>
#include "partition.h"

const int NMAX = 1e2;
const int SMAX = 4e4;
const int BITS = 25;

using namespace std;

vector<int> fr[BITS + 5];
int n;

std::vector<int> solve(std::vector<int> A) {
    n = (int)A.size();

    fill(fr, fr + BITS + 2, vector<int>());
    for (int i = 0; i < n; ++i) {
        int cur = A[i], p = 0;
        while (cur % 2 == 0) {
            cur /= 2;
            ++p;
        }

        // assert(p <= BITS);

        fr[p].push_back(i);
    }

    vector<int> p1;
    vector<int> p2;
    for (int i = 0; i <= BITS; ++i) {
        if (!fr[i].empty()) {
            int cate = fr[i].size() / 2;

            for (int j = 0; j < cate; ++j) {
                p1.push_back(fr[i].back());
                fr[i].pop_back();
            }

            for (int j = 0; j < cate; ++j) {
                p2.push_back(fr[i].back());
                fr[i].pop_back();
            }
        }
    }

    vector<int> rem;
    for (int i = 0; i <= BITS; ++i){
        if (!fr[i].empty()) {
            rem.push_back(fr[i].back());
        }
    }

    if (!rem.empty()) {
        int sz = rem.size();
        for (int i = 0; i < (sz - 1) / 2; ++i)
            p1.push_back(rem[i]);

        p1.push_back(rem[sz - 1]);
        for (int i = (sz - 1) / 2; i < sz - 1; ++i)
            p2.push_back(rem[i]);
    }

    vector<int> ans;
    for (auto &it : p1)
        ans.push_back(it);

    for (auto &it : p2)
        ans.push_back(it);

    return ans;
}

#ifndef EVAL
#include<iostream>
#include<vector>
using namespace std;
extern vector<int> solve(vector<int> A);
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t ;
    for (int test=1; test<=t; test++) {
        int n;
        cin >> n ;
        vector <int> a(n);
        for (int i=0; i<n; i++) {
            cin >> a[i] ;
        }

        for (auto ind : solve(a)) {
            cout << ind << " ";
        }
        cout << endl ;
    }
    cout << endl ;
    return 0;
}
#endif