from sys import stdin,stdout
from math import gcd,sqrt
from collections import deque
input=stdin.readline
R=lambda:map(int,input().split())
I=lambda:int(input())
S=lambda:input().rstrip('\n')
L=lambda:list(R())
P=lambda x:stdout.write(x)
hg=lambda x,y:((y+x-1)//x)*x
pw=lambda x:1 if x==1 else 1+pw(x//2)
chk=lambda x:chk(x//2) if not x%2 else True if x==1 else False
N=10**10+7
for _ in range(I()):
	n=I()
	a=sorted(R(),reverse=True)
	b=[a[0]]
	a.remove(a[0])
	g=b[0]
	for i in range(1,n):
		mx=0
		id=0
		for j in range(n-i):
				v=gcd(g,a[j])
				if v>mx:
					mx=v
					id=a[j]
		g=mx
		b+=id,
		a.remove(id)
	print(*b)