def gcd(x, y): 
      
    while(y): 
        x, y = y, x % y 
      
    return x 

t=int(raw_input())
for r in range(t):
    n=int(raw_input())
    a= map(int, raw_input().split(" "))
    m=0
    for i in range(n):
        m=max(m,a[i])
    ans=[]
    for i in range(n):
        av= 0
        ind= -1
        for j in range(n):
            if a[j]==-1:
                continue
            if gcd(m,a[j])>av:
                av=gcd(m,a[j])
                ind=j
        ans.append(a[ind])
        a[ind]=-1
        m=av
    print " ".join(map(str, ans))

