from math import gcd
t = int(input())
for _ in range(t):
	n = int(input())
	arr = sorted([int(p) for p in input().split()], reverse=True)
	f = arr[0]
	final = sorted(arr, key=lambda x: gcd(f, x), reverse=True)
	print(*final)