def ii():  return int(input())
def si():  return input()
def mi():  return map(int,input().strip().split(" "))
def msi(): return map(str,input().strip().split(" "))
def li():  return list(mi())

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


for _ in range(ii()):
    n=ii()
    a=li()
    
    f=[0]*(n+5)
    
    a.sort(reverse=True)
    
    ans=[a[0]]
    f[0]=1
    g=a[0]
    
    while len(ans)!=n:
    
        mx=0
        pos=-1
    
    
        for i in range(n):
    
    
            if f[i]==0:
    
                if gcd(g,a[i])>mx:
                    mx=gcd(g,a[i])
                    pos=i
    
    
     
    
        f[pos]=1
        ans.append(a[pos])
        g=gcd(g,a[pos])
    
    print(*ans)