import sys
import math as mt
import collections as cc
import sys
import itertools as it
I=lambda:list(map(int,input().split()))
input=sys.stdin.readline
for tc in range(int(input())):
	n,=I()
	l=I()
	ma=max(l)
	if 1:
		ev=l
		ans=[ma]
		ev.remove(ma)
		now=ma
		while ev:
			temp=now
			te=-1
			ele=-1
			for j in ev:
				if mt.gcd(j,temp)>te:
					te=mt.gcd(j,temp)
					ele=j
			now=te
			ans.append(ele)
			ev.remove(ele)
		print(*ans)
