from math import gcd
for i in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    ans = [max(a)]
    gr=ans[-1]
    vis = [0] * len(a)
    while(len(ans)!=n+1):
        mx = -1
        mx_ind=-1
        for i in range(len(a)):
            if (vis[i] != 1):
                tmp=gcd(gr, a[i])
                if (mx < tmp):
                    mx = tmp
                    mx_ind = i
        gr=mx
        vis[mx_ind] = 1
        ans.append(a[mx_ind])
    ans.pop(0)
    print(*ans)
