

import math
import collections
def gcd(a,b):
	return a if b == 0 else gcd(b,a % b)
def f(n,ais):
	ais.sort(key = lambda x:-x)
	g = ais[0]
	for i in range(1,len(ais)):
		gg,jj = max([(gcd(ais[j],g),j) for j in range(i, len(ais))])
		g = gg
		ais[i],ais[jj] = ais[jj],ais[i]
	return ais
for _ in range(int(raw_input())):
	n = int(raw_input())
	ais = map(int ,raw_input().split())
	print ' '.join(map(str,f(n,ais)))