import math
tst =int(input())

t=1
while t<=tst:
    n=int(input())
    ls=list(map(int,input().split()))
    mx=max(ls)
    ls1=[0]*mx
    ans=[]
    ls.sort(reverse=True)
    d=ls[0]
    ans.append(ls[0])
    i=1
    while i<n:
        g=0
        pos=0
        j=1
        mx1=0
        while j<n:
            if ls[j]!=-1 and math.gcd(ls[j],d)>g:
                mx1=math.gcd(ls[i],d)
                pos=j
            j+=1
        ans.append(ls[pos])
        ls[pos]=-1
        d=mx1
        i+=1
    i=0
    while i<n:
        print(ans[i],end=" ")
        i+=1
    print("\r")

    t+=1