#include<bits/stdc++.h>

using namespace std;

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define vi vector<int>

const int N = 100005;

void solve() {
	int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
	cin >> n;
	int a[n];
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	cout << a[0] << " ";
	int vis[n] = {};
	vis[0] = 1;
	cnt = a[0];
	for (i = 0; i < n - 1; i++) {
		ans = -1;
		int id = -1;
		for (j = 0; j < n; j++) {
			if (vis[j]) continue;
			if (ans == -1 || __gcd(a[j], cnt) > __gcd(ans, cnt)) {
				ans = a[j];
				id = j;
			}
		}
		cnt = ans;
		vis[id] = 1;
		cout << ans << " ";
	}
	cout << '\n';
	return ;
}

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