//  --        --------       ||        --           -------   |      |       ,,,,       ___________
//	-  --           /       / \      -  --       /           |      |     ,,,  ,,,          |
//	-    --     ---        / __ \     -    --     *-----*     |'''''' |    ,,      ,,         |
//	-  --           \     /     \     -  --            /     |	    |     ,,,  ,,,          |
//	--        --------    /       \    --        -------      |      |       ,,,,            |
 
#include <iostream>
#include<bits/stdc++.h>
#include <algorithm>
#include <array>
#include <cassert>
#include <vector>
#define pb push_back
#define mp make_pair
#define endl '\n'
 
#define IOS  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define loop(i,start,n) for(i=start;i<n;i++)
#define rloop(i,end,n) for(i=end-1;i>=n;i--)
#define mod 1000000007
typedef long long ll;
using namespace std;
const ll N=1e5+1;
#define clr(x)  memset(x, 0, sizeof(x))
#define mp make_pair
 
 
long long int power(long long int x,long long int n)
{
    long long int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}
 
int main() 
{
	
	ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,ans=0;
    cin>>a;
    while(a--)
    {
        
        cin>>b;
        ll A[b],B[b],C[100000]={0};
        loop(c,0,b)
        {
            cin>>A[c];
        }
        sort(A,A+b, greater<ll>());
        B[0]=A[0];
        C[0]=1;
        loop(c,1,b)
        {
            e=0;
            f=0;
            loop(d,0,b)
            {
                if(C[d]!=1 && __gcd(B[0],A[d])>e)
                {
                    e=__gcd(B[c-1],A[d]);
                    f=d;
                }
            }
            C[f]=1;
            B[c]=A[f];
        }
        loop(c,0,b)
        {
            cout<<B[c]<<" ";
        }
        cout<<endl;
    }
    return 0;
}