#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);
		for(auto &x:v)cin >>x;

		sort(ALL(v),greater<int>());
		vector<pii> ans;
		ans.pb({v[0],v[0]});
		int x=v[0];
		for(int i=1;i<n;i++){
			ans.pb({__gcd(v[0],v[i]),v[i]});
		}
		sort(ALL(ans),greater<pii>());
		for(int i=0;i<n;i++){
			cout << ans[i].y<<" ";
		}cout <<endl;
	}
	
	return 0;
}
