from math import gcd
for q in range(int(input())):
	n = int(input())
	a = sorted(list(map(int, input().split())), reverse = True)
	
	ind = -1
	g = a[0]
	j = 1
	while j < n:
		tmp = 0
		for i in range(j, n):
			y = gcd(g, a[i])
			if y > tmp:
				tmp = y
				ind = i
		a[j], a[ind] = a[ind], a[j]
		g = tmp
		j+=1
	print(*a)
	