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

t=int(input())
for i in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    a=[]
    a.append(max(arr))
    arr.remove(max(arr))
    k=len(arr)
    l=len(arr)-1
    prev=a[0]
    for i in range(1,k+1):
        m=0
        ans=0
        for j in range (l+1):
           
            if gcd(prev,arr[j])==max(m,gcd(prev,arr[j])):
                m=gcd(prev,arr[j])
                ans=arr[j]
          
        a.append(ans)
        arr.remove(ans)
        
        prev=m
        l-=1
    
    for i in range(len(a)):
        print(a[i]," ", end="")