import math
for _ in range(int(input())):
    n=int(input())
    a=list(map(int, input().split()))
    c=[]
    b=[]
    maxi=max(a)
    c.append(maxi)
    b.append(maxi)
    a[a.index(maxi)]=0
    current=1
    current_gcd=0
    value=-1
    while current<n:
        for i in range(len(a)):
            if a[i]!=0:
                if math.gcd(c[current-1],a[i])>current_gcd:
                    index=i
                    value=a[i]
                    current_gcd=math.gcd(c[current-1],a[i])
                    
                    
        b.append(value)
        c.append(current_gcd)
        a[index]=0
        current_gcd=0
        value=-1
        current+=1
        
    for i in b:
        print(i,end=" ")
    print()
        
                    
                
            
