/* ****_hela**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  1005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	cin>>TESTS;
	while(TESTS--)
	{
		ll n;
		cin>>n;
		vector<int>a(n);
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		sort(all(a));
		vector<int>ans;
		ans.pb(a[n-1]);
		int end=n-2;

		vector<bool>vis(N,0);
		vis[n-1]=1;
		for(int i=1;i<n;i++){
			int ind=0,flg=1,gcd=0,ch;
			while(ind<=n-2){
				if(!vis[ind])
				{
					int temp=__gcd(ans.back(),a[ind]);
					//cout<<"ans.back(): "<<ans.back()<<","<<a[ind]<<": "<<temp<<'\n';
								if(temp>gcd){
									ch=ind;
									gcd=temp;
								}
				}
				ind++;
			}
			//cout<<"i: "<<i<<" a[ch]:"<<a[ch]<<'\n';
			ans.pb(a[ch]);
			vis[ch]=1;
		}
		for(auto i:ans)
			cout<<i<<" ";
		cout<<'\n';
	}
	return 0;
}