from math import gcd
for tt in range(int(input())):
    n = int(input())
    a = sorted(list(map(int,input().split())))
    ans = []
    ans.append(a.pop())
    cur = ans[0]
    for i in range(n-1):
        best = 0
        l = 0
        for j in a:
            if gcd(j,cur) >= l:
                l = gcd(j,cur)
                best = j
        ans.append(best)
        a.remove(best)
        cur = l
    print(*ans)
