import math
for _ in range(int(input())):
    size=int(input())
    l=list(map(int,input().split()))
    ans=[]
    ans.append(max(l))
    l.remove(max(l))
    k=ans[-1]
    while(len(l)!=0):
        maxi=0
        index=0
        for i in range(len(l)):
            temp=maxi
            maxi=max(maxi,math.gcd(k,l[i]))
            if maxi!=temp:
                index=l[i]
        ans.append(index)
        k=math.gcd(k,ans[-1])
        l.remove(index)
    ans=list(map(str,ans))
    ans=" ".join(ans)
    print(ans)