import sys
import math
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	a = LI()
	a.sort(reverse=True)
	ans = [a.pop(0)]
	gcd = ans[0]
	for i in range(len(a)):
		m = 0
		ind = -1
		for j in range(len(a)):
			g = math.gcd(a[j],gcd)
			if g>m:
				m = g
				ind = j
		gcd = m
		ans.append(a.pop(ind))
	print(*ans)
