# 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+5)
        try:
            ans = [a[0]]
            f[0] = 1
            g = a[0]
            while len(ans) != n:
                mx = 0
                pos = -1
                for i in range(n):
                    if f[i] == 0:
                        if gcd(g, a[i]) > mx:
                            mx = gcd(g, a[i])
                            pos = i
                f[pos] = 1
                ans.append(a[pos])
                g = gcd(g, a[pos])
        except:
            pass
        print(" ".join(map(str, ans)))


main()
