from math import gcd
for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    b = []
    fl = [0] * n
    g = max(a)
    b = [g]
    fl[a.index(g)] = 1
    for i in range(1, n):
        cur = -1
        for j in range(n):
            if fl[j]:
                continue
            cur = max(cur, gcd(g, a[j]))
        for j in range(n):
            if fl[j]:
                continue
            if cur == gcd(g, a[j]):
                fl[j] = 1
                g = cur
                b.append(a[j])
                break
    print(*b)