#include<bits/stdc++.h>    
#define int long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second 
#define mod 1000000007     
using namespace std;

void solve(){
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr, arr + n, greater<int>());
    vector<bool> visit(n, false);
    vector<int> ans;
    ans.pb(arr[0]);
    visit[0] = true;
    for(int i = 0; i < n - 1; i++){
        int mx = -1, id = -1, ele = -1;
        for(int j = n - 1; j >= 0; j--){
            if(visit[j])
                continue;
            if(__gcd(ans.back(), arr[j]) > mx){
                mx = __gcd(ans.back(), arr[j]);
                id = j;
                ele = arr[j];
            }
        }
        visit[id] = true;
        ans.pb(ele);
    }
    for(auto to: ans)
        cout << to << ' ';
    cout << endl;
}

main()
{    
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
}