import math
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    c=[a[-1]]
    b=[0]*n
    b[-1]=1
    d=1
    g=c[0]
    while d!=n:
        m=0;ind=-1
        for i in range(n):
            if  b[i]==0:
                k=math.gcd(g,a[i])
                if k>m:
                    m=k
                    ind=i
        c+=[a[ind]]
        b[ind]=1
        d+=1
        g=m
    print(*c)







