#include<bits/stdc++.h>
#define pb push_back
#define sf scanf
#define pf printf
using namespace std;
#define ll long long
const int N=1e5+9;
void slv()
{
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a.rbegin(),a.rend());
    vector<int>ans;
    map<int,int>vis;
    for(int i=0;i<n;i++) {
        if(!vis[i]) {
            ans.push_back(a[i]);
            vis[i]=1;
        }
        int mxgcd=0,idx=0;
        //cout<<i<<" X "<<ans.size()<<endl;
        for(int j=i+1;j<n;j++) { 
            //cout<<"jj "<<j<<endl;
            int gcd=__gcd(ans.back(),a[j]);
            if(gcd > mxgcd) {
                mxgcd=gcd;
                idx=j;
            }
        } 
        //puts("x");
        if(!vis[idx]) {vis[idx]=1;
        ans.push_back(a[idx]); }
    }
    for(auto it : ans) cout<<it<<" ";
    cout<<endl;
}
int main()
{
    //cout<<__gcd(96,128)<<endl;
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int t;
    cin >> t;
    while (t--)
    {
        slv();
    }
    return 0;
}
