from sys import stdin
input=lambda : stdin.readline().strip()
from math import ceil,sqrt,factorial
from collections import deque
from bisect import bisect_left
def gcd(a,b):
	while a%b!=0:
		a,b=b,a%b
	return b
for _ in range(int(input())):
	n=int(input())
	l=list(map(int,input().split()))
	d={}
	ma=0
	ans=[]
	for i in l:
		if i in d:
			d[i]+=1
		else:
			d[i]=1
		ma=max(ma,i)
	ans.append(ma)
	d[ma]-=1
	if d[ma]==0:
		d.pop(ma)
	x=ma
	for i in range(n-1):
		ma=0
		f=0
		for i in d:
			t=gcd(max(x,i),min(x,i))
			if t>ma:
				ma=t
				f=i
		ans.append(f)
		x=ma
		d[f]-=1
		if d[f]==0:
			d.pop(f)
	print(*ans)