#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long int
using namespace std;

int fact(int n){
    if(n==1)
        return 1;

    return n*fact(n-1);
}

int ncr(int n,int r){
    if(n==r || r==0)
        return 1;

    return fact(n)/(fact(r)*fact(n-r));
}

int power(int a,int n){
    int res=1;
    while(n>0){
        if(n%2==1){
            n--;
            res*=a;
        }
        n/=2;
        a*=a;
    }
    return res;
}


void solve(){
    int n;
    cin>>n;
    int a[n];
    map<int,int> mp;
    for(int i=0;i<n;i++){
        cin>>a[i];
        mp[a[i]]=1;
    }
    sort(a,a+n,greater<int>());
    cout<<a[0]<<" ";
    mp[a[0]]=0;
    for(int i=2;i<=a[0];i++){
        if(a[0]%i==0 && mp[a[0]/i]==1){
            cout<<a[0]/i<<" ";
            mp[a[0]/i]=0;
        }
    }
    vector<int> ans;
    for(auto i:mp){
        if(i.second==1)
            ans.push_back(i.first);
    }
    sort(ans.begin(),ans.end(),greater<int>());
    for(auto i:ans){
        cout<<i<<" ";
    }
    cout<<endl;
}

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	#ifndef ONLINE_JUDGE
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
//	#endif
    int t;
    cin>>t;
    while(t--){
    solve();
    }
    return 0;
}