from math import gcd
cases=int(input())
for _ in range(cases):
	n=int(input())
	c=list(map(int,input().split()))
	d=sorted(c)[::-1]
	if len(d)==1:
		print(*d)
	else:
		w=gcd(d[0],d[1])
		l=[d[0]]
		for i in range(1,len(d)):
			l.append(gcd(l[0],d[i]))
			
		w=list(zip(d,l))
		w=sorted(w,key=lambda x:x[1])[::-1]
		x=[]
		for i in range(len(w)):
			x.append(w[i][0])
		print(*x)
	
	
	
	
	
