# cook your dish 
def gcd(a,b):
    if a<b:
        a,b=b,a
    while(b>1):
        if a%b==0:
            return b
        a,b=b,a%b
    return 1    
t=int(input())
for i in range(t):
    n=int(input())
    ar=[int(k) for k in input().split()]
    ans=[]
    mark=[0 for j in range(n)]
    ans.append(max(ar))
    mark[ar.index(max(ar))]=1
    curgc=ans[0]
    mxgc=None
    ans1=None
    for j in range(n-1):
        # print(mark)
        for k in range(n):
            if mark[k]!=1:
                if mxgc==None or gcd(curgc,ar[k])>mxgc:
                    mxgc=gcd(curgc,ar[k])
                    ans1=k
        mark[ans1]=1
        curgc=mxgc
        mxgc=None
        # print(ans1)
        ans.append(ar[ans1])
    for k in ans:
        print(k, end=" ")
    print("")
        
        
            
    