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

#define ll long long int
#define forr(i,n) for(int i=0;i<n;i++)
#define f(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) int t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vi vector<ll>
const ll mod=1e9 +7;const ll M1=998244353;
ll power(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;x=x*x;y=y>>1;}return res;}
bool isprime(ll n) 
{ 
    f(i,2,n+1){
        int a=0;
        while(n%i==0){n/=i;a++;if(a>1)return false;}
    }
    return true; 
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    CASE(t){
        int n;cin>>n;
        vector<int> v(n);
        f(i,0,n)cin>>v[i];
        sor(v);rev(v);
        ce(v[0]);int d=v[0],mx=-1,ind=-1;int mxg=0;v[0]=-1;
        f(i,0,n){
            ind =-1;mx=-1;d=-2;mxg=0;
            f(j,1,n){
                if(v[j]!=-1)if(__gcd(d,v[j])>=mxg){mxg=__gcd(d,v[j]);mx=v[j];ind=j;}
            }
            if(ind==-1){
                f(j,1,n){if(v[j]!=-1){ce(v[j]);d=v[j];v[j]=-1;break;}}
            }else if(ind>=0){
                ce(v[ind]);d=v[ind];v[ind]=-1;
            }

        }
        f(i,0,n){
            if(v[i]!=-1){ce(v[i]);}
        }
        cout<<endl;

    }
    

}