from math import gcd
q = int(input())
for _ in range(q):
    n = int(input())
    s = list(map(int, input().split()))
    s.sort()
    c = [s[-1]]
    seen = {n - 1}
    y = s[-1]
    while len(c) < n:
        tmp, res, ind = 0, 0, 0
        for i in range(n):
            if i not in seen:
                x = gcd(y, s[i])
                if x > tmp:
                    tmp, res, ind = x, s[i], i
        c.append(res)
        seen.add(ind)
        y = tmp
    print(*c)
