#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int maxn = 1e5+7;
const ll MOD = 998244353;

int n, t;
bool ok[maxn];
int arr[maxn];
int c[maxn];

int main()
{
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) scanf("%d", &arr[i]), ok[i] = true;
        sort(arr+1 , arr+1+n);
        c[1] = arr[n], ok[n] = false;
        for(int i = 2; i <= n; i++)
        {
            int mm;
            for(int j = 1; j <= n; j++) if(ok[j]) {mm = j; break;}
            for(int j = 1; j <= n; j++)
                if(ok[j] && __gcd(c[i-1] , arr[j]) > __gcd(c[i-1] , arr[mm]))
                    mm = j;
            c[i] = arr[mm];
            ok[mm] = false;
        }
        for(int i = 1; i <= n; i++) printf("%d ", c[i]);
        printf("\n");
    }
    return 0;
}
