# import sys
# input = lambda: sys.stdin.readline().rstrip()
import sys
import math
input = sys.stdin.readline
from collections import deque
from queue import LifoQueue

def binary_search(a, n):
	L = 0
	R = len(a)-1
	while L<=R:
		mid = L+(R-L)//2
		if a[mid]==n:
			return mid
		elif a[mid]<n:
			L = mid+1
		else:
			R = mid-1
	return -1

for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	ans = [a[-1]]
	print(a[-1],end=' ')
	di = {}
	for i in a:
		if di.get(i,False):
			di[i]+=1
		else:
			di[i] = 1
	a.pop()
	# fl = ans[-1]
	fact = []
	for i in range(ans[0],0,-1):
		if ans[0]%i==0:
			fact.append(i)
	# print(fact)
	for i in fact:
		for j in range(1,(ans[0]//i)+2):
			if j*i in a:
				# cnt = 0
				# for pp in a:
				# 	if j*i==pp:
				# 		cnt+=1
				cc = [i*j]*di[i*j]
				print(*cc,end=' ')
				a.pop(binary_search(a,j*i))

	print()