import math
tst =int(input())

t=1
while t<=tst:
    n=int(input())
    ls=list(map(int,input().split()))
    ans=[]
    mx=max(ls)
    d=mx
    ans.append(mx)
    i=0
    while i<n:
        pos=0
        j=0
        g=0
        while j<len(ls):
            if ls[j]!=mx and ls[j]!=-1 and (math.gcd(ls[j],d))>g:
                g=math.gcd(ls[j],d)
                pos=j
            j+=1
        ans.append(ls[pos])
        ls[pos]=-1
        d=g
        i+=1
    i=0
    while i<n:
        print(ans[i],end=" ")
        i+=1
    print("\r")
    t+=1