from math import gcd
import operator
for _ in range(int(input())):
  t = int(input())
  a = list(map(int, input().split()))
  if t == 1:
    print(a[0])
  else:
    a = sorted(set(a))
    p = a[-1]
    d = a[:-1]
    q = {}
    for i in d:
      q[i] = gcd(p,i)


    q = sorted(q.items(),key=operator.itemgetter(1),reverse=True)
    w = str(p) + " "
    for i in q:
      w += str(i[0]) + " "
    print(w.strip())