import math
for _ in range(int(input())):
	n = int(input())
	l = list(map(int,input().split()))
	l.sort(reverse=True)
	
	arr = []
	arr.append(l[0])
	res = l[0]
	for i in range(1,n):
		mx = -1000000
		idx = -1
		for j in range(1,n):
			if l[j] != -1:
				ans = math.gcd( res , l[j])
				if ans > mx :
					mx = ans
					idx = j

		
		res = math.gcd(res,l[idx])
		arr.append(l[idx])
		l[idx] = -1
	print(*arr)

