from sys import stdin
import sys
g   = lambda : stdin.readline().strip()
gl  = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1e9)+7
inf = float("inf")
 
from sys import setrecursionlimit
import threading
 
def main():
	def gcd(a,b): 
	    if (b == 0): 
	         return a 
	    return gcd(b, a%b) 
  
	t, = gil()
	for _ in range(t):			
		n, = gil()
		a = gil()
		a.sort()
		vis = [0]*n
		vis[-1] = 1
		ans = [a.pop()]
		cgcd = ans[0]
		for i in range(1, n):
			new = [0, 0]
			for j in range(n):
				if vis[j] == 0 :
					newGcd = gcd(a[j], cgcd)
					if newGcd > new[0]:
						new = [newGcd, j]
			cgcd = new[0]
			j = new[-1]
			vis[j] = 1
			ans.append(a[j])

		for v in ans :
			print(v, end=" ")
		print()




 


 
setrecursionlimit(10000)
threading.stack_size(10**8)
t = threading.Thread(target=main)
t.start()
t.join()
 