import math
for _ in range(int(input())):
    n = int(input())
    L=list(map(int,input().split()))
    m = max(L)
    ans = []
    ans.append(m)
    L.remove(m)
    while(len(L)>0):
        g,e = -1,0
        for i in range(len(L)):
            if(math.gcd(m,L[i]) > g):
                g = math.gcd(m,L[i])
                e = L[i]
        m = g
        L.remove(e)
        ans.append(e)
    print(*ans)
