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

for _ in range(int(input())):
    
    n = int(input())
    arr = list(map(int,input().split()))
    
    arr.sort(reverse = True)
    ans = [arr[0]]
    tmp = arr[0]
    arr.pop(0)
    n -= 1 
    
    while(n>0):
        maxx = 0
        item = 0
        for i in arr:
            if gcd(tmp,i)>=maxx:
                maxx = gcd(tmp,i)
                item = i 
            
        tmp = maxx
        arr.remove(item)
        n -= 1 
        ans.append(item)
        
    print(*ans)