def gcd(x,y):
    if(x%y==0):
        return y
    return gcd(y,x%y)
t=int(input())
for you in range(t):
    n=int(input())
    l=input().split()
    li=[int(i) for i in l]
    l=[]
    li.sort()
    li.reverse()
    done=[0 for i in range(n)]
    l.append(li[0])
    done[0]=1
    curr=li[0]
    for j in range(1,n):
        z=0
        for i in range(n):
            if(done[i]==1):
                continue
            p=gcd(curr,li[i])
            if(p>z):
                z=p
                ans=i
        done[ans]=1
        l.append(li[ans])
        curr=gcd(curr,li[ans])
    for i in l:
        print(i,end=" ")
    print()