import sys
import math 
from decimal import *
def I(): return int(sys.stdin.readline())
def IL(): return list(map(int,sys.stdin.readline().strip().split()))
def ILS(): return list(map(str,sys.stdin.readline().strip().split()))

def solve():
	tt = I()
	for ii in range(tt):
		n = I()
		l = IL()
		l.sort(reverse = True)
		# print(l)
		ans = [l[0]]
		cg = l[0]
		l[0] = -1
		while len(ans) < n :
			# print(l)
			x = None
			tg = None
			for i in range(1,len(l)):
				if l[i] != -1 :
					if x == None : x =i;tg = math.gcd(l[i],cg) 
					else : 
						ttg = math.gcd(cg,l[i])
						if ttg >tg :
							x = i
							tg = ttg
					# print(i,x,tg) 

			ans.append(l[x])
			cg = tg 
			l[x] = -1
		for aa in ans :
			print(aa,end=" ")
		print()
solve()