#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


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

	int ff = *max_element(all(a));
	ump<int, int>mp;
	mp[ff]++;

	int lastgcd = ff;
	int maxgcd, currgcd;
	int lastele;
	cout << ff << " ";
	for (int z = 1; z < n; z++)
	{
		maxgcd = -1;
		for (int j = 0; j < n; j++)
		{
			if (mp.find(a[j]) != mp.end()) continue;
			else
			{
				currgcd = gcd(lastgcd, a[j]);
				if (currgcd > maxgcd)
				{
					maxgcd = currgcd;
					lastele = a[j];
				}
			}

		}
		mp[lastele]++;
		cout << lastele << " ";
		lastgcd = maxgcd;
	}

	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;
}