from math import gcd
def main():
    for _ in range(int(input())):
        n=int(input())
        a=list(map(int,input().split( )))
        checkAngela=[1]*n
        m=max(a)
        ans=[]
        ans.append(m)
        checkAngela[a.index(m)]=0
        currwhite=ans[0]
        length=1
        while 1:
            if length==n:
                break
            ind=-1
            temp=0
            for i in range(n):
                if checkAngela[i]:
                    if gcd(currwhite,a[i])>temp:
                        temp=gcd(currwhite,a[i])
                        ind=i
            if ind!=-1:
                ans.append(a[ind])
                checkAngela[ind]=0
                length+=1
                currwhite=gcd(currwhite,a[ind])
        print(*ans)
main()
                    
        
        