def gcd(a, b):  
    if a == 0 : 
        return b  
      
    return gcd(b%a, a) 
T=int(input()) 
for t in range(T):
    N=int(input()) 
    A=list(map(int,input().split())) 
    A.sort() 
    A.reverse() 
    B=[]
    C=[0]*N   
    g=A[0]  
    for i in range(N):
        mx=1 
        ind=i  
        for j in range(0,N):
            if C[j]!=-1:
                gc=gcd(g,A[j])
                if mx<=gc:
                    mx=gc 
                    ind=j
        g=gcd(g,mx)  
        C[ind]=-1 
        B.append(A[ind]) 
        #print(g,B,mx)     
    for b in B:
        print(b,end=' ') 
    print('')  