from math import gcd
for _ in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    d = [0 for i in range(n)]
    m1 = max(l)
    r = [m1]
    d[l.index(m1)]=1
    p=m1
    for i in range(n-1):
        m=0
        x=0
        for j in range(n):
            g = gcd(p,l[j])
            if m==0 and d[j]!=1 and g>m:
                m=g
                x=j
            elif m>0 and d[j]!=1 and g>m:
                m=g
                x=j
            elif m>0 and d[j]!=1 and g==m:
                if l[j]>l[x]:
                    m=g
                    x=j
        r.append(l[x])
        d[x]=1
        p=gcd(l[x],p)
    print(*r)