t = int(input())
for _ in range(t):
    from math import gcd
    n = int(input())
    a = list(map(int, input().split()))
    b = []
    b.append(max(a))
    a.pop(a.index(max(a)))
    c = b[0]
    for i in range(n - 1):
        m = 1
        k = 0
        for j in range(n - 1 - i):
            if gcd(a[j], c) > m:
                k = j
                m = gcd(a[j], c)
        c = m
        b.append(a[k])
        a.pop(k)
    print(*b)
