from math import gcd
t = int(input())

for _ in range(t):

    n = int(input())
    l = list(map(int,input().split()))
    l.sort(reverse=True)
    ans = [0]
    g = 0
    seti = {0}
    for i in range(1,n):
        g = gcd(g,l[ans[i-1]])
        z = 0
        maxi = 0
        ind = -1
        # seti = {0}
        for j in range(n):
            if j not in seti:
                if gcd(g,l[j])>maxi:
                    maxi = gcd(g,l[j])
                    ind = j

        seti.add(ind)
        ans.append(ind)

    la = [l[i] for i in ans]
    print(*la)



