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

t = int(input())

for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    b = []
    m = 0
    for j in range(n):
        if len(b) == 0:
            k = max(a)
            m = k
        else:
            m0 = 0
            for x in a:
                r = gcd(x, m)
                if r > m0:
                    m0 = r
                    k = x

            m = m0

        b.append(k)
        a.remove(k)

    print(' '.join(str(x) for x in b))
