from math import *
from bisect import *
from collections import Counter,defaultdict,deque
I=lambda:int(input())
M =lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
for _ in range(I()):
  n=I()
  a=LI()
  b=[0]*n
  a.sort()
  c=[a[-1]];b[-1]=1;d=1
  g=c[0]
  while d!=n:
    m=0;ind=-1
    for i in range(n):
      if not b[i]:
        k=gcd(g,a[i])
        if k>m:
          m=k;ind=i
    c+=[a[ind]]
    b[ind]=1;d+=1;g=m
  print(*c)



    









    

            







        
