from math import gcd
from collections import Counter

def upd(val, coua, bp, rem):
	p, q = -1, None
	for ele in coua:
		r = gcd(val, ele)
		if r > p:
			q = ele
			p = r
	bp += [q for x in range(coua[q])]
	rem -= coua[q]
	val = p
	del coua[q]
	return val, coua, bp, rem

for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	ma = max(a)
	cma = sum(x == ma for x in a)
	bp = [ma for x in range(cma)]
	coua = Counter(a)
	del coua[ma]
	val = ma
	rem = n - cma
	while val != 1 and rem != 0:
		val, coua, bp, rem = upd(val, coua, bp, rem)

	if rem:
		bp += [x for x in coua.elements()]
	print(*bp)