from math import gcd

def read_line():
    return list(map(int, input().split()))

T = int(input())
for _ in range(T):
    n = int(input())
    l = list(reversed(sorted(read_line())))
    ans = [l[0]]
    l.remove(l[0])
    g = ans[0]
    while True:
        if len(l) == 0:
            break
        max_n = -1
        max_n_val = -1
        for k in l:
            b = gcd(g, k)
            if b > max_n:
                max_n = b
                max_n_val = k
        ans.append(max_n_val)
        l.remove(max_n_val)
        g = max_n
    print(" ".join(map(str, ans)))

