from sys import stdin
from math import gcd
input = stdin.buffer.readline

for _ in range(int(input())):
	n = int(input())
	*a, = map(int, input().split())
	g = max(a)
	a.remove(g)
	print(g, end=' ')
	for i in range(n - 1):
		x = mx = 0
		for j in a:
			if mx < gcd(g, j):
				mx = gcd(g, j)
				x = j
		a.remove(x)
		g = mx
		print(x, end=' ')
	print()
