from sys import stdin


def inp():
    return stdin.buffer.readline().rstrip().decode('utf8')


def itg():
    return int(stdin.buffer.readline())


def mpint():
    return map(int, stdin.buffer.readline().split())


# ############################## import
def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x
# ############################## main
from collections import Counter
for __ in range(itg()):
    n = itg()
    arr = list(mpint())
    arr.sort()
    gg = arr.pop()
    ans = [gg]
    counter = Counter(arr)
    while counter:
        best_key, best_value = None, 0
        for key in counter.keys():
            g = gcd(key, gg)
            if g > best_value:
                best_key, best_value = key, g
            elif g == best_value:
                best_key = max(best_key, key)

        ans.append(best_key)
        gg = gcd(gg, best_key)
        counter[best_key] -= 1
        if counter[best_key] == 0:
            del counter[best_key]
    print(*ans)

# Please check!
