from math import log2, ceil

def readGenerator():
    while True:
        tokens = input().split(' ')
        for t in tokens:
            yield t

reader = readGenerator()

def readWord():
    return next(reader)

def readInt():
    return int(next(reader))

def readFloat():
    return float(next(reader))

def readLine():
    return input()

def solve(a):
    a = list(reversed(sorted(a)))
    b = [a[0]]
    u = [False] * len(a)
    u[0] = True
    g = a[0]
    for i in range(len(a) - 1):
        max = -1
        pos = -1
        for j in range(0, len(a)):
            if not u[j]:
                gc = gcd(g, a[j])
                if gc > max:
                    max = gc
                    pos = j
        g = gcd(g, a[pos])
        b.append(a[pos])
        u[pos] = True
    return ' '.join(map(str, b))

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

tests = readInt()

for i in range(tests):
    n = readInt()
    a = [readInt() for _ in range(n)]
    print(solve(a))