from math import gcd
 
for _ in range(int(input())):
	n=int(input())
	l=list(map(int,input().split()))
	xo=0
	ans=[]
	while l:
		t=max(l,key=lambda x: gcd(x,xo))
		xo=gcd(t,xo)
		ans.append(t)
		l.remove(t)
	print(*ans)