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