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

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> arr(n);
        for(int i=0;i<n;i++){
            cin >> arr[i];
        }
        sort(arr.begin(),arr.end());
        reverse(arr.begin(),arr.end());
        
        vector<int> ans;
        ans.push_back(arr[0]);
        arr.erase(arr.begin());
        int gcd = arr[0];
        int prev = arr[0];
        int temp = arr[0];
        for(int i=1;i<n;i++){
            int l = 0,r = arr.size(),mid,del ;
            while(l<r){
                mid = (l+r)/2;
                int needed = __gcd(arr[mid],gcd); 
                if(needed <= prev and temp>=needed){
                    temp = needed;
                    del = mid;
                    r = mid - 1;
                }
                else{
                    
                    l = mid + 1;
                }
            }
            ans.push_back(arr[del]);
            arr.erase(arr.begin()+del);
            gcd = temp;
        }
        for(auto i:ans){
            cout << i<< " ";
        }
        cout<<endl;
    }
    return 0;
}