import sys
from math import ceil, gcd
from collections import deque

# input = sys.stdin.buffer.readline
# def print(val):
# 	sys.stdout.write(str(val) + '\n')

for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	a.sort(reverse = True)
	# print(a)
	b = []
	g = a[0]
	b.append(a[0])
	a.pop(0)
	# print(a)
	mx = 1
	nx = 0
	while a:
		mx = 1
		nx = 0
		for i in range(len(a)):
			if gcd(g, a[i])>=mx:
				mx = gcd(g, a[i])
				nx = i
				# print(mx, nx, end=' **** ')
		# print(g)
		g = gcd(g, mx)
		# print(nx, 'xxxx')
		b.append(a[nx])
		a.pop(nx)
	for i in b:
		print(i, end=' ')
	print()
