#include <bits/stdc++.h>

using namespace std;

//#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")

#define ff first
#define ss second
#define vt vector
#define pb push_back
#define ppb pop_back
#define all(a) a.begin(), a.end()
#define ent "\n"
#define sp ' '
#define sz(x) (int)x.size()

using ll  = long long;
using db  = double;
using ldb = long double;
using pll = pair <ll, ll>;
using pii = pair <int, int>;

const ll  INF = 8e18;
const ll  inf = 1e9 + 7;
const int MOD = 998244353;
const int bln = 200;
const int M   = 2e3 + 7;
const int N   = 2e5 + 7;

/*-------------------------main-------------------------*/
/*

*/

int a[N];
int pw;
set<int> st[bln];
map<int, int> cnt1;
int calc[N][20], calc1[N][20];
void solve() {
    #define test
    int n;
    cin >> n;
    map<int, int> cnt;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= 20; ++j) {
            if(j == 0) calc[i][j] = i;
            else calc[i][j] = calc[i][j - 1] / 2;
        }
        for(int j = 0; j <= 20; ++j) {
            if(j == 0) calc1[i][j] = i;
            else calc1[i][j] = calc1[i][j - 1] * 2 + 1;
        }
    }
    if(n == 1) {
        cout << a[1];
        return;
    }
    vector<int> newA;
    for(auto cur : cnt) {
        st[cur.second].insert(cur.first);
        newA.pb(cur.first);
    }
    while((1 << pw) < n) pw++;
    if(sz(st[pw]) != 1) {
        cout << -1;
        return;
    }
    for(int i = pw - 1; i >= 1; --i) {
        if(sz(st[i]) != (1 << (pw - i - 1))) {
            cout << -1;
            return;
        }
    }
    do {
        set<int> x;
        for(int i = 0; i < sz(newA); ++i) x.insert(i + (1 << (pw - 1)));
        bool flag = 1;
        for(int i = 1; i < pw; ++i) {
            int start = *x.begin();
            x.erase(x.begin());
            for(int j = start; j < (1 << pw); j += (1 << i)) {
                int pos = j;
                pos = calc[pos][i];
                pos = calc1[pos][i];
                if(newA[pos - (1 << (pw - 1))] > newA[j - (1 << (pw - 1))]) {
                    flag = 0;
                }
                if(!st[i].count(newA[j - (1 << (pw - 1))])) {
                    flag = 0;
                }
                x.erase({j});
            }
        }
        if(flag) {
            for(auto cur : newA) cout << cur << " ";
            cout << "\n";
            return;
        }
    } while(next_permutation(all(newA)));
    cout << -1;
}

void precalc() {

}

signed main() {
//  freopen("lca.in", "r", stdin);
//  freopen("lca.out", "w", stdout);

    precalc();
    int testcases;
    #ifdef tests
        cin >> testcases;
    #endif
    #ifdef test
        testcases = 1;
    #endif
    while (testcases--) {
        solve();
    }
    return 0;
}
