t = int(input())

for ii in range(t):

	n = int(input())

	a = list(map(int, input().split()))

	a.sort(reverse = True)

	ans = [a[0]]

	used = [False]*n

	used[0] = True

	def gcd(a, b):
		if a%b == 0:
			return b

		return gcd(b, a%b)
		
	maxgcdsofar = ans[-1]

	for i in range(n-1):
		done = 0
		idx = None
		# print(maxgcdsofar)
		for j in range(1, n):
			if not used[j]:
				num = gcd(maxgcdsofar, a[j])
				# print(num, maxgcdsofar, a[j])
				if num > done:
					done = num
					idx = j

		ans.append(a[idx])
		maxgcdsofar = done
		used[idx] = True

	print(*ans)
