/*
    Name:Amzad Hussain Tamim
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define S second
#define F first
#define mem(a, b)     memset(a, b, sizeof(a))
#define pii          pair<ll,ll>
#define bug(a)       cerr << #a << " : " << a << endl;
#define BaChao     ios_base::sync_with_stdio(false);cin.tie(NULL);

#define D(x) cerr << #x " is " << x << endl
//int fx[4] = {-1, 0, 0, 1};
//int fy[4] = {0, -1, 1, 0};
//int fx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
//int fy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
/*
Note :  There is a problem with erase() function in ordered_multiset (for less_equal<ll> tag).
        lower_bound() works as upper_bound() and vice-versa.
        Be careful to use.
        i) find_by_order(k) : kth smallest element counting from 0 .
        ii) order_of_key(k) : number of elements strictly smaller than k.
*/

/******************************************
#Rows are numbered from top to botom.
#Columns are numbered from left to right.
Moves : L, U, R, D, LU, RU, RD, LD.
Lower bound e >=
Upper bound e >b
******************************************/
const int MOD=1e9+7;
/*...... ! Code starts from here ! ......*/
const int MX=5;
int fx[]= {+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]= {-1,+1,+0,+0,+1,+1,-1,-1};
ll mx=1e20;
int lcm(int x, int y)
{
    return (x*y)/__gcd(x,y);
}
int main()
{
    BaChao
    int n,x,t,k;
    cin>>t;
    while(t--)
    {
        cin>>n;
        vector<int>a(n);
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        if(n==1)
        {
            cout<<a[0]<<endl;
            continue;
        }
        sort(a.begin(),a.end());
        vector<pair<int,int>>now;
        int mx=a[n-1];
        cout<<mx<<" ";
        for(int i=0;i<a.size()-1;i++)
        {
            //cerr<<__gcd(mx,a[i])<<" -- "<<a[i]<<endl;
          now.pb({__gcd(mx,a[i]),a[i]});
        }
        sort(now.rbegin(),now.rend());
        for(int i=0;i<now.size();i++)
        {
            cout<<now[i].S<<" ";
        }
        cout<<endl;

    }
}

