def gcd(a,b):
    while a*b:a%=b;a,b=b,a
    return a
for _ in range(int(input())):
    n = int(input())
    lis = sorted(map(int,input().split()),reverse = True)
    prev=lis[0]
    for i in range(1,n):
        tmp=ind=0
        for j in range(i,n):
            t = gcd(prev,lis[j])
    #        print(t,prev)
            if t>tmp:
                tmp=t
                ind=j
    #    print(ind,i,prev)
        prev=tmp
        lis[ind],lis[i]=lis[i],lis[ind]
    #    print(lis)
    print(*lis)
        
