import sys
import math


def f(a, n):
    a.sort(reverse=True)
    b, vst = [a[0]], {0}
    d = a[0]
    while len(vst) < n:
        gcd, next = 1, -1
        for i in range(len(a)):
            if i not in vst:
                if a[i] == d:
                    gcd, next = d, i
                    break
                tmp = math.gcd(d, a[i])
                if tmp >= gcd:
                    gcd, next = tmp, i
        b.append(a[next])
        vst.add(next)
        d = gcd
    return b


t = int(sys.stdin.readline().strip())
for _ in range(t):
    n = int(sys.stdin.readline().strip())
    a = list(map(int, sys.stdin.readline().strip().split()))
    out = f(a, n)
    for i in range(n-1):
        sys.stdout.write("%d " % out[i])
    sys.stdout.write("%d\n" % out[-1])

