def gcd(a,b): 
      
    # Everything divides 0  
    if (b == 0): 
         return a 
    return gcd(b, a%b)
    
for _ in range(int(input())):
    n=int(input())
    arr=list(map(int,input().split()))
    x=max(arr)
    b=[x]
    arr.remove(x)
    
    for i in range(n-1):
        temp=-1
        k=0
        m=0
        
        for j in range(n-1):
            if arr[j]!=-1:
                
                if gcd(x,arr[j])>temp:
                    k=j
                    m=arr[j]
                    temp=gcd(x,arr[j])
        b.append(m)
        arr[k]=-1
        x=temp
    
    b=list(map(str,b))
    s=" ".join(b)
    print(s)