from math import gcd
n = int(input())
for _ in range(n):
    f = int(input())
    ans =[]
    l = list(map(int,input().split()))[:f]
    ans.append(max(l))
    cur = ans[-1]
    l.remove(ans[-1])
    while len(l)>0:
        best = 0
        i = 0
        for j in l:
            if gcd(j,cur)>i:
                i = gcd(cur,j)
                best =j
        ans.append(best)
        l.remove(best)
        cur = i
    print(*ans)    
                
            
            
    
    
