import sys
sys.setrecursionlimit(10**8)
try: 
	FILE_POINTER = open('input.inpt')
	input = FILE_POINTER.readline
except: 
	FILE_POINTER = None
	input = sys.stdin.readline

# ********************* Write your code from here ********************

def gcd(a,b):
	if a == 0:
		return b
	return gcd(b%a, a)

t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	arr.sort(key = lambda x : -x)
	
	ans = [arr[0]]
	gcdtill = arr[0]
	arr[0] = -1
	for i in range(n-1):
		mx = 0
		nxt = 0
		for j in range(n):
			if arr[j] != -1:
				gcdj = gcd(gcdtill, arr[j])
				if gcdj > mx:
					mx = gcdj
					nxt = j
		ans.append(arr[nxt])
		arr[nxt] = -1
		gcdtill = mx
	for i in ans:
		print(i, end = " ")
	print()
		
	
# *********************      Code ends here       ********************	
	
if FILE_POINTER:
	FILE_POINTER.close()