for t in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    base=0
    for i in range(n):
        base=max(base,a[i])
    maxi=base
    visit=[0 for i in range(maxi+1)]
    for i in range(n):
        visit[a[i]]+=1
    c=[]
    i=base
    while(i>0):
        j=maxi
        while(j>0):
            if(visit[j]>0 and j%i==0 and base%i==0):
                for k in range(visit[j]):
                    c.append(j)
                visit[j]=0
                base=i
            j-=1
        i-=1
    for i in c:
        print(i,end=' ')
    print()
