import math
t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().rstrip().split()))
    a.sort()
    g=a[-1]
    ans=[g]
    mx=0
    ind=-1
    v=[0]*n
    v[-1]=1
    ct=0
    for i in range(1,n):
        ct=0
        for j in range(n):
            if v[j]==0:
                if ct==0:
                    g1=math.gcd(a[j],g)
                    ind=j
                    ct+=1
                else:
                    t=math.gcd(a[j],g)
                    if t>g1:
                        g1=t
                        ind=j
        g=g1
        v[ind]=1
        ans.append(a[ind])
    for i in ans:
        print(i,end=" ")
    print()
                        