// #include "partition.h"
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
//#define int long long

std::vector<int> solve(std::vector<int> A){
    int n=A.size();
    // cout<<n<<endl;
    vector <pair <int,int> > a;
    for(int i=0;i<n;i++){
        a.pb(make_pair(A[i],i));
    }
    sort(a.begin(),a.end());
    vector <int> vec,vec1;
    vector <bool> vis(n+5,0);
    // cout<<n<<endl;
    for(int i=1;i<n;i++){
        if(a[i].ff==a[i-1].ff){
            vec.pb(a[i].ss);
            vec1.pb(a[i-1].ss);
            // cout<<i<<" "<<i<<endl;
            vis[i]=1;
            vis[i-1]=1;
            i++;
            continue;
        }
    }
    
    int mx=-1,idx=-1;
    for(int i=0;i<n;i++){
        if(vis[i]==0){
            mx=max(mx,a[i].ff);
            idx=i;
        }
    }
    if(mx!=-1){
        vec.pb(a[idx].ss);
        vis[idx]=1;
        for(int i=0;i<n;i++){
            if(vis[i]==0){
                vec1.pb(a[i].ss);

            }
        }
    }
    for(auto u:vec1){
        vec.pb(u);
    }
    return vec;

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