from collections import defaultdict
from math import gcd
for _ in range(int(input())):
	n = int(input())
	a = list(map(int,input().split()))
	a.sort(reverse = True)
	res = [a[0]]
	val = a[0]
	k = 1
	lol = [[0,a[i]] for i in range(n)]
	while (k<n):
		ans = []
		for i in range(k,n):
			ans.append([gcd(val,lol[i-k+1][1]),lol[i-k+1][1]])
		lol = sorted(ans,key = lambda x:-x[0])
		res.append(lol[0][1])
		val = gcd(val,lol[0][1])
		k+=1
	print(*res)
