from math import gcd
t = int(input())
for _ in range(t):
	n = int(input())
	arr = sorted([int(p) for p in input().split()], reverse=True)
	final = [arr[0]]
	ele = 0
	g = arr[0]
	arr.pop(0)
	while arr:
		ele = 0
		curr = None
		for i in range(len(arr)):
			prev = ele
			ele = max(ele, gcd(arr[i], g))
			if prev != ele:
				curr = arr[i]
		final.append(curr)
		arr.remove(curr)
		g = gcd(curr, g)
		
	print(*final)