#https://codeforces.com/problemset/problem/1407/B
def gcd(a,b):
	if a%b==0:
		return b
	return gcd(b,a%b)
for _ in range(int(input())):
	n=int(input())
	l=list(map(int,input().split()))
	d={}
	for i in l:
		if i in d:
			d[i]+=1
		else:
			d[i]=1
	s=list(d.keys())
	x=[max(s)]
	s.remove(x[0])
	cgcd=x[0]
	while len(s):
		temp=0
		ans=None
		for i in s:
			if gcd(cgcd,i)>temp:
				temp=gcd(cgcd,i)
				ans=i
		cgcd=temp
		x.append(ans)
		s.remove(ans)
	for i in x:
		print(*[i]*d[i],end=' ')
	print()
		
