import math

t=int(input())
for _ in range(t):
    n=int(input())
    lst=list(map(int,input().strip().split()))
    lst=sorted(lst,reverse=True)
    n=len(lst)
    ans=lst[0]
    for i in range(1,n):
        for j in range(i+1,n):
            if (math.gcd(ans,lst[i]))<(math.gcd(ans,lst[j])):
                
                (lst[j],lst[i])=(lst[i],lst[j])
        ans=math.gcd(ans,lst[i])        
    print(*lst)                
                    