#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define pob pop_back
#define mp make_pair
#define ff first
#define ss second
#define pi 3.14159265
#define lb lower_bound
#define ub upper_bound
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <ll, ll> pll;
const ll M=1e9+7;
ll expo(ll a,ll b){if(b==0)return 1;if(b%2==0){ll ret=expo(a,b/2);ret=(ret*ret)%mod;return ret;}else{ll ret=expo(a,b/2);ret=(ret*ret)%mod;ret=(ret*a)%mod;return ret;}}
bool is_prime(int x){for(int i=2;i*i<=x;i++)if(x%i==0)return false;return true;}
ll inf=1e18;
int main()
{
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        vector <int> v(n);
        for(int i=0;i<n;i++)
            cin>>v[i];
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        vector <int> c;
        set <int> s;
        int g=v[0];
        c.pb(v[0]);
        int a=1;
        s.insert(v[0]);
        while(1){
        for(int i=0;i<n;i++){
            if(s.find(v[i])==s.end() && (__gcd(v[i],g)>=__gcd(a,g))){
                a=v[i];
            }
        }
        if(a!=1){
            g=__gcd(g,a);
            c.pb(a);
            s.insert(a);
            a=1;
        }
        else{
            for(int i=0;i<n;i++){
                if(s.find(v[i])==s.end())
                    c.pb(v[i]);
            }
            break;
        }
        }
        for(int i=0;i<n;i++)
            cout<<c[i]<<" ";
        cout<<endl;
    }
}
