from collections import Counter
for i in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    b=sorted(a,reverse=True)
    ans=[]
    maxi=b[0]

    c=[]
    for j in range(1,maxi+1):
        if maxi%j==0:
            c.append(j)
    c.sort(reverse=True)

    for j in (c):

        for k in range(len(b)):
             if j>b[k]:
                 break
             if b[k]%j==0:
                ans.append(b[k])
                b[k]=999999999999
             elif j==b[k]:
                ans.append(b[k])
    for j in ans:
        if j<=maxi:
            print(j,end=" ")
    print("")





