from math import gcd
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    ans = [max(a)]
    g = ans[0]
    s = set([a.index(g)])
    for _ in range(n - 1):
        ma, mi = 0, 0
        for i in range(n):
            if i not in s:
                k = gcd(g, a[i])
                if k > ma:
                    mi = i
                    ma = k
        ans.append(a[mi])
        s.add(mi)
    print(*ans)
            
