from sys import stdin
from math import gcd
"""
n=int(stdin.readline().strip())
n,m=map(int,stdin.readline().strip().split())
s=list(map(int,stdin.readline().strip().split()))
"""
T=int(stdin.readline().strip())
for caso in range(T):
    n=int(stdin.readline().strip())
    s=list(map(int,stdin.readline().strip().split()))
    s.sort()
    s=s[::-1]
    ans=[s[0]]
    s.remove(s[0])
    last=ans[0]
    for i in range(n-1):
        mx=-1
        a=-1
        for j in s:
            z=gcd(j,last)
            if z>mx:
                mx=z
                a=j
        ans.append(a)
        s.remove(a)
        last=gcd(last,a)
    print(*ans)
            
            
            
                
                
                    

