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

#define int   long long
#define gcd   __gcd
#define pb    push_back
#define pf    push_front
#define em    emplace        //use in place of insert(x) or insert(position,x)
#define emb   emplace_back
#define pof   pop_front
#define pob   pop_back
#define ump   unordered_map
#define mpr    make_pair
#define fs    first
#define sc    second
#define deq   deque
#define stk   stack
#define LETSGO int TESTCASES;cin>>TESTCASES;while(TESTCASES--)
#define fr(a,b,c) for(int a=b;a<c;a++)
#define setbit(x) __builtin_popcount(x)
#define all(el) el.begin(),el.end()
#define BOOM ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pinf LLONG_MAX
#define ninf LLONG_MIN


bool srt(pair<int, int>p1, pair<int, int>p2)
{
	if (p1.second > p2.second)
		return true;
	else
		return false;
}

void solveTestCases()
{
	int n;
	cin >> n;
	std::vector<int>a(n);
	fr(i, 0, n) cin >> a[i];

	sort(all(a)); reverse(all(a));

	vector<pair<int, int>>gpair;

	cout << a[0] << " ";

	fr(i, 1, n)
	{
		gpair.pb({a[i], gcd(a[0], a[i])});
	}


	sort(gpair.begin(), gpair.end(), srt);

	fr(i, 0, n - 1)
	{
		cout << gpair[i].first << " ";
	}

	cout << endl;
	return;
}

int32_t main() {
	BOOM
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	LETSGO
	solveTestCases ();


	return 0;
}



