from math import gcd
for _ in range(int(input())):
	n=int(input())
	arr=list(map(int,input().split()))
	arr.sort(reverse=True)
	m=arr[0]
	res=[arr[0]]
	del arr[0]
	
	currgcd=m
	while(arr):
		m=-1
		ind=-1
		el=-1
		
		for i in range(len(arr)):
			gc=gcd(currgcd,arr[i])
			
			if gc>m:
				m=gc
				ind=i
				el=arr[i]
		currgcd=gcd(el,currgcd)
		res.append(el)
		del arr[ind]
	print(*res)