from math import gcd
for _ in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    l.sort()
    ans = [l[-1]]
    l.remove(l[-1])
    kk = 0
    tt = ans[0]
    while(l):
        kk = 0
        for i in l:
            d = gcd(i,tt)
            if d>=kk:
                kk = d
                pp = i
        tt = kk
        l.remove(pp)
        ans.append(pp)
    print(*ans)
            

