
// Problem : B. Big Vova
// Contest : Codeforces - Codeforces Round #669 (Div. 2)
// URL : https://codeforces.com/contest/1407/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("O2")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
int main()
{
	fast;
	ll t = 1;
	cin >> t;
	while (t--)
	{
		ll n;
		cin >> n;
		ll a[n];
		for(ll i=0;i<n;i++)
			cin>>a[i];
		sort(a,a+n,greater<int>());
		vector<ll> v;
		for(ll i=0;i<n;i++)
		{
			if(a[i] != -1)
				v.push_back(a[i]);
			for(ll j=i+1;j<n;j++)
			{
				if(a[j] != -1 && a[i]%a[j] == 0)
				{
					v.push_back(a[j]);	
					a[j] = -1;
				}
			}
		}
		for(auto i:v)
			cout<<i<<" ";
		cout<<"\n";
	}
	return 0;
}
