from fractions import gcd

for _ in range(input()):
    n=input()
    ans=[]
    l=map(int,raw_input().split())
    if n==1:
        print l[0]
    else:
        mx=max(l)
        ans=[mx]
        l[l.index(mx)]=-1
        while len(ans)<n:
            t=0
            ind=-1
            for i in range(n):
                if l[i]!=-1:
                    if gcd(mx,l[i])>t:
                        t=gcd(l[i],mx)
                        ind=i
            mx=t
            ans.append(l[ind])
            l[ind]=-1
        for i in ans:
            print i,
        print