#include <bits/stdc++.h>
using namespace std;

#define ll long long int



ll mod(ll x){
    if(x>=0){
        return x;
    }else{
        return -x;
    }
}

bool compare(pair<ll,ll>p1,pair<ll,ll>p2){
    if(p1.first!=p2.first){
        return p1.first > p2.first;
    }else{
        return p1.second<p2.second; 
    }
    
}

void solve(vector<ll>&v,ll n){
    sort(v.begin(),v.end());
   
    vector<ll>ret;
    ll last = v[n-1];
    vector<pair<ll,ll>>v1;
    for(ll i=0;i<n-1;i++){
        ll value = __gcd(last,v[i]);
        v1.push_back(make_pair(value,i));
    }
    
    sort(v1.begin(),v1.end(),compare);
    ret.push_back(last);
    for(ll i=0;i<n-1;i++){
        ret.push_back(v[v1[i].second]);
    }
    
    for(ll i=0;i<n;i++){
        cout << ret[i] << " ";
    }
    
    
    cout << endl;
    
    
    
    
    
    
}









int main() {
  ll t;
  cin>>t;
  while(t--){
      ll n;
      cin>>n;
      vector<ll>v;
      for(ll i=0;i<n;i++){
          ll x;
          cin>>x;
            v.push_back(x);
          
      }
      
      solve(v,n);
      
     

    
  }
    
}