from math import gcd
def solution(a):
	b=list()
	g = max(a)
	for i in range(len(a)):
		temp=0;ans=0
		for j in range(len(a)):
			if a[j] not in b:
				temp = gcd(g,a[j])
			if temp > ans:
				ans = temp
				idx = j
		g = ans		
		b.append(a[idx])
	for i in b:
		print(i, end=' ')
			
t = int(input())

for i in range(t):
	n = int(input())
	a = list(map(int,input().split()))
	solution(a)
	