#include "bits/stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

using namespace std;

const double EPS = 1e-11;
const double PI = 2 * acos(0.0);
using ll = long long;
using ull =  unsigned long long;

#define input freopen("C:/Users/rsssu/Desktop/input.txt", "r", stdin)
#define output freopen("C:/Users/rsssu/Desktop/output.txt", "w", stdout)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#define pf printf
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define sll(x,y) scanf("%lld %lld",&x,&y)

#define pii pair<int,int>
#define nl '\n'
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())
#define out(x) cout <<"#x = "<<x<<endl
#define outt(x,y) cout <<"# "<<x<<" "<<y<<endl
#define mem(array,value) memset(array,value,sizeof(array))

//int setBit(int N,int pos){return N=N | (1<<pos);}
//int reset(int N,int pos){return N= N & ~(1<<pos);}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
//EWNS
//int dx[]={+1,-1,+0,+0};
//int dy[]={+0,+0,+1,-1};
//int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
//int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};

bool f[1006];
int main()
{
	#ifdef TEST
		input;
		output;
	#endif
	int t;
	//int Case=0;
	si(t);
	while (t--) {
		
		int n;
		cin >>n;
		vector<int> v(n),ans(n);
		for(auto &x:v){
			cin >>x;
		}
		sort(ALL(v),greater<int>());
		int mx=v[0];
		f[mx]=1;
		ans[0]=mx;
		for(int i=1;i<n;i++){
			int g=0;
			int idx=0;
			for(int j=0;j<n;j++){
				int GCD =  __gcd(mx,v[j]);
				if(!f[v[j]] && GCD >g){
					g=GCD;
					idx=j;
				}
			}
			ans[i]=v[idx];
			f[v[idx]]=1;
			mx=g;
		}
		for(auto c:ans)cout <<c<<" ";
		cout <<endl;
		mem(f,0);
	}
	
	return 0;
}
