def gcd(a, b):
    a = abs(a)
    b = abs(b)
    while b != 0:
        a, b = b, a % b
    return a


def solve(a):
    b = []
    b.append(a.pop())
    g = b[len(b) - 1]     
    for i in range(len(a)):
        k = -1
        m = 0
        for j in range(len(a) - 1, -1, -1):
            gc = gcd(g, a[j])
            if gc > m:
                m = gc
                k = j
        b.append(a[k])
        g = m
        a.pop(k)
    return b

N = int(input())
for i in range(N):
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    print(*solve(a))
    