import sys,math as mt
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))


sv=[0]*(1002)
pr=[]
for i in range(2,len(sv)):
	if sv[i]==0:
		sv[i]=i
		pr.append(i)
		for j in range(2*i,len(sv),i):
			sv[j]=i
def div(n):
	dv=[]
	i=0
	while pr[i]<=int(n**0.5):
		if n%pr[i]==0:
			dv.append(pr[i])
		i+=1
	return dv
t,=I()
for _ in range(t):
	n,=I()
	l=I()
	x=max(l)
	l=sorted(l,reverse=True)
	an=[x]
	l.remove(x)
	while l:
		gd=0;el=1
		for k in l:
			if mt.gcd(k,x)>gd:
				gd=mt.gcd(k,x)
				el=k
		x=gd
		an.append(el)
		l.remove(el)
	print(*an)