ii = lambda :  int(input())
il = lambda :  list(map(int, input().split()))
for _ in range(ii()):
    def find_gcd(x, y): 
        while(y): 
           x, y = y, x % y 
        return x 
    n=ii()
    a=il()
    a.sort(reverse=True)
    gcd=a[0]
    ans=[a[0]]
    for i in range(0,n):
        mx=0
        for i in range(1,len(a)):
            mx=max(mx,find_gcd(gcd,a[i]))
        for i in range(1,len(a)):
            ld=find_gcd(gcd,a[i])
            if(ld==mx):
                ans.append(a[i])
                a[i]=-1
                gcd=mx
                break
    for i in range(0,n):
        print(ans[i],end=" ")
    print("")