import sys
import math
from collections import defaultdict,Counter

# input=sys.stdin.readline
# def print(x):
#     sys.stdout.write(str(x)+"\n")

# sys.stdout=open("CP1/output.txt",'w')
# sys.stdin=open("CP1/input.txt",'r')

# mod=pow(10,9)+7
t=int(input())
for i in range(t):
	n=int(input())
	a=list(map(int,input().split()))
	c=Counter(a)
	ma=max(a)
	l=[ma]
	c[ma]-=1
	if c[ma]==0:
		del(c[ma])
	g=ma
	for i1 in range(1,n):
		cur=[0,0]
		for j in c:
			g1=math.gcd(g,j)
			if g1>cur[0]:
				cur=[g1,j]
		c[cur[1]]-=1
		g=cur[0]
		l.append(cur[1])
		if c[cur[1]]==0:
			del(c[cur[1]])
	print(*l)
