# cook your dish here
import math
for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    mgcd=max(l)
    l.remove(max(l))
    k=[]
    k.append(mgcd)
    #print(k,"  ",l)
    while len(l)>0:
        ans=0
        ind=0
        for i in range(len(l)):
            kk=math.gcd(mgcd,l[i])
            if kk>ans:
                ans=kk
                ind=i
        k.append(l[ind])
        mgcd=math.gcd(mgcd,ans)
        l.remove(l[ind])
       # print(k,"           ",l)
    print(*k)