def computeGCD(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 



t=int(input())
 
while(t>0):
 
	t-=1
	n=int(input())
	arr=[int(x) for x in input().split()]
	dp=[[0 for x in range(n)] for x in range(n)]

	temp=max(arr)
	ans=[]
	ans.append(temp)
	arr.remove(temp)
	
		
	if len(arr)>1:
		while(len(arr)>1):
			mx=0
			a=0
			for i in range(len(arr)):
				gcd=computeGCD(temp,arr[i])
				if gcd>mx and arr[i]!=temp:
					mx=gcd 
					a=arr[i]
			ans.append(a)
			arr.remove(a)
			temp=a
	#print(arr)
	if len(arr)==1:
		ans.append(arr[0])

	for i in range(len(ans)):
		print(ans[i],end=" ")
	print()

		