import math
t = int(input())

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

while t>0:
  n = int(input())
  a = list(map(int, input().split()))
  a.sort(reverse=True)
  b = [a[0]]
  seen = [False]*n
  seen[0] = True
  c = b[0]
  for j in range(1,n):
    max_index = 0
    max_elem = 0
    for i in range(0,n):
      ci = gcd(c,a[i])
      if not seen[i] and ci > max_elem:
        max_index = i
        max_elem = ci
    b.append(a[max_index])
    c = max_elem
    seen[max_index] = True
  print(" ".join(str(num) for num in b))
  t-=1
