from sys import stdin, stdout
def gcd(a,b): 
    if (b==0): 
        return(a)  
    return gcd(b,a%b) 
t=int(stdin.readline())
for _ in range(t):
    n=int(stdin.readline())
    x=list(map(int,stdin.readline().split()))
    x.sort(reverse=True)
    g=0
    for i in range(n):
        maxi=0
        ind=-1
        for j in range(n):
            if x[j]==-1:
                continue
            tmp=gcd(g,x[j])
            if tmp>maxi:
                ind=j
                maxi=tmp
        print(x[ind],end=" ")
        g=gcd(x[ind],g)
        x[ind]=-1
    print()


            
