def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


gans = []
for _ in range(int(input())):
    n = int(input())
    u = list(map(int, input().split()))
    ans = []
    cur = max(u)
    a = [0] * n
    a[u.index(cur)] = 1
    ans.append(cur)
    for i in range(1, n):
        ansi = -1
        ind = -1
        for j in range(n):
            if a[j]:
                continue
            g = gcd(cur, u[j])
            if g > ansi:
                ansi = g
                ind = j
        a[ind] = 1
        ans.append(u[ind])
        cur = ansi
        #print(ansi)
    gans.append(' '.join(map(str, ans)))
print('\n'.join(gans))
