#include <iostream>
#include <algorithm>

using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
#define LL unsigned long long
#define RI register int
#define pr(x) cout<<#x<<" = "<<x<<endl;
#define p(x) cout<<x<<endl;
#define SP <<"   "<<
int t,n;
//1 6 1 1 0 0 0 0
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		int a[n+3];
		for(RI i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		sort(a+1,a+1+n,cmp);
		int t=a[1];
		bool b[n+1]={0};
		//cout<<"输出：";
		for(RI i=1;i<=n;i++)
		{
			if(t%a[i]==0)
			{
				//cout<<"$"; 
				cout<<a[i]<<" ";
				b[i]=1;
			}
		}
		for(RI i=1;i<=n;i++)
		{
			if(!b[i])	cout<<a[i]<<" ";
		}
		cout<<endl;
	}
}