import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]

def gcd(a,b):
	if b < a:
		a,b = b, a

	if a == 0:
		return b

	return gcd(b%a, a)

testCases = int(input())
answers = []
for _ in range(testCases):
	#take input
	#n2 would work

	n = int(input())
	arr = input_split()

	#to create a perm of a = barr
	#such that carr with ci = gcd(b0, b1,.. bi-1) is lexi max
	maxi = max(arr)
	# pending = set(pending)
	# pending.discard(maxi)
	arr.remove(maxi)
	barr = [maxi]
	g = maxi
	for i in range(n-1):
		temp = [(gcd(g, a), a) for a in arr]
		g, to_remove = max(temp)
		barr.append(to_remove)
		arr.remove(to_remove)
		# chosen = None
		# for j in range(len(arr)):


	answers.append(barr)

for a in answers:
	print(*a, sep = " ")
# print(*answers, sep = '\n')

