
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    
    x=max(a)
    ans=[x]
    for i in range(n):
        if a[i]==x:
            a.pop(i)
            break
        
    while len(a)!=0:
        n=len(a)
        m=0
        for j in range(n):
            aa=gcd(x,a[j])
            if aa>m:
                ind=j
                m=aa
                
        ans.append(a[ind])
        x=gcd(x,a[ind])
        a.pop(ind)

    
    print(*ans)
            