import io
import os
import sys
import math

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

fileno = sys.stdin.fileno()
input = io.BytesIO(
	os.read(fileno, os.fstat(fileno).st_size)
).readline


T = int(input())
for t in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	A.sort(reverse=True)
	used = [False for i in range(N)]
	B = [A[0]]
	used[0] = True
	prefix_gcd = A[0]
	for i in range(1, N):
		best_gcd = 0
		best_j = None
		for j in range(1, N):
			if used[j]:
				continue
			current_gcd = math.gcd(prefix_gcd, A[j])
			if current_gcd > best_gcd:
				best_gcd = current_gcd
				best_j = j
				# best gcd we can get
				if best_gcd == prefix_gcd:
					# print("break")
					break
		used[best_j] = True
		prefix_gcd = best_gcd
		B.append(A[best_j])
		if prefix_gcd == 1:
			for k in range(1, N):
				if not used[k]:
					B.append(A[k])
			break
	print(' '.join(map(str, B)))