# not my code
# https://codeforces.com/contest/1407/submission/92248591

# Author : raj1307 - Raj Singh
# Date   : 08.09.2020


def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


def main():
    for _ in range(int(input())):
        n = int(input())
        a = sorted(list(map(int, input().split())), reverse=True)
        f = [0]*n
        ans = [0]*n
        ans[0] = a[0]
        f[0] = 1
        prev = a[0]
        k = 1
        for k in range(1, n):
            mx, pos = max([(gcd(prev, ai), i) for i, ai in enumerate(a) if f[i] == 0])
            f[pos] = 1
            ans[k] = a[pos]
            prev = gcd(prev, a[pos])
        print(" ".join(map(str, ans)))


main()
