from math import gcd
t = int(input())
while t != 0:
    n = int(input())
    a = list(map(int, input().split()))[:n]
    ans = [max(a)]
    g = [max(a)]
    a.remove(max(a))
    for i in range(n-1):
        high = 0
        maxi = 0
        for j in a:
            high = gcd(g[-1], j)
            if high > maxi:
                maxi = high
                k = j
        ans.append(k)
        g.append(maxi)
        a.remove(k)
    print(*ans)
    t -= 1
        
            
