from math import gcd
from collections import Counter
for _ in range(int(input())):	
	n=int(input())
	lis=list(map(int,input().split()))
	max1=max(lis)
	output=[max1]
	dic=Counter(lis)
	dic[max1]-=1
	if dic[max1]==0:
		del dic[max1]
	gcd1=max1
	while(len(output)!=len(lis)):
		max1=0
		
		for i in dic:
			if gcd(gcd1,i)>max1:
				max1=gcd(gcd1,i)
				element=i 
		dic[element]-=1
		output.append(element)
		if dic[element]==0:
			del dic[element]
		gcd1=max1
	for i in output:
		print(i,end=" ")
	print()
