from math import gcd
for t in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    a.reverse()
    g=a[0]
    for i in range(1,n):
        m=0
        s=i
        for j in range(i,n):
            gc=gcd(g,a[j])
            #print(g,a[j],gc)
            if(gc>m):
                #print(a[j])
                s=j
                m=gc
        a[i],a[s]=a[s],a[i]
        #print(a)
        g=m

    print(*a,sep=" ")