#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vs vector<string>
#define pb push_back
#define rep(i,n) for(int i = 0;i<n;i++)
#define repk(k,n) for(int i = k;i<n;i++)
#define all(v) v.begin(),v.end()
#define print(v) for(auto n:v){cout << n << "\t";}
#define input(v) for(auto &i:v){cin >> i;}
#define mod 1000000007
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);

ll max(ll a, ll b){
	return a>b?a:b;
}
using namespace std;

void solve(){
	ll n;
	cin >> n;
	vi v(n);
	input(v);
	map<int,int>mp;
	map<int,int>mp2;
	int t = *max_element(all(v));
	sort(all(v),greater<int>());
	int k = n-1;
	set<int>s;
	int prev = t;
	s.insert(prev);
	while(k--){
		int p = 0;
		int res = 0;
		for(int i = 0;i<n;i++){
			int temp = v[i];
			if(s.count(v[i])==0){
				int kk = __gcd(prev,temp);
				if(kk>p){
					p = kk;
					res = temp;
				}
				if(kk==p){
					if(res<temp){
						res = temp;
					}
				}
			}
		}
		// cout << prev << " "<<  res <<endl;
		// cout << " k = " << k << endl;
		mp[prev] = res;
		prev = res;
		s.insert(res);
	}
	// for(auto i:mp){
	// 	cout << i.first << " " << i.second << endl;
	// }
	k = n-1;
	cout << t << " ";
	while(k--){
		cout << mp[t] << " ";
		t = mp[t];
	}

	cout << endl;
	

}


int main(){
	ll t = 1;
	cin >> t;
	while(t--){
		solve();
	}

	return 0;
}