from math import gcd 

for _ in range(int(input())):
	n = int(input())
	l = sorted(map(int,input().split()))
	gd = [l[-1]]

	l.remove(l[-1])
	mx = gd[-1]
	while len(l) > 0:
		num, mx_gcd = 0, 0
		for i in l:
			temp = gcd(i,mx)
			if temp > mx_gcd:
				num = i
				mx_gcd = temp

		gd.append(num)
		l.remove(num)
		mx = gcd(mx,num)


	for i in range(n):
		print(gd[i], end=" ")

	print()