def gcd(a,b): 
    # Everything divides 0  
    if (b == 0): 
         return a 
    return gcd(b, a%b) 

t=int(input())
while(t):
    t-=1
    n=int(input())
    arr=list(map(int,input().split()))
    arr.sort(reverse=True)
    ans=[]
    ans.append(arr[0])
    visited=[0]*n
    visited[0]=1
    lastgc=arr[0]
    for i in range(1,n):
        maxi=-1
        index=-1
        original=''.join(str(x) for x in ans)
        s1=original
        for j in range(n):
            if(visited[j]!=1):
                gc=gcd(lastgc,arr[j])
                
                if(gc>maxi):
                    maxi=gc
                    index=j
                    s1=original+str(gc)
        visited[index]=1
        ans.append(arr[index])
        lastgc=maxi
    print(' '.join(str(i) for i in ans))



