from math import gcd 
for _ in " "*int(input()):
  n=int(input())
  a=list(map(int,input().split()))
  if n == 1:
    print(*a)
  elif n == 2:
    print(max(a),min(a))
  else:
    x = max(a)
    a[a.index(x)] = -1 
    g=0
    cnt=0
    print(x,end=" ")
    ind = 0
    while(True):
      if cnt == n-1:
        break
      for i in range(n):
        if a[i] != -1:
          if gcd(x,a[i]) >= g:
            xx=a[i]
            ind = i
            g=gcd(x,a[i])
      print(xx,end=" ")
      cnt+=1
      x = a[ind]
      a[ind] = -1
      g=0
    print()