def gcd(a,b):
    if b==0:
        return a
    aa=a%b
    return gcd(b,aa)

def check(lst,m):
    g=False
    ans=0
    for i in lst:
        if m%i==0 and ans<i:
            ans=i
            g=True
    if g==False:
        gcm=0
        for i in lst:
            k=gcd(m,i)
            if k>gcm:
                ans=i
                gcm=k
    return ans

t=int(input())
for _ in range(t):
    n=int(input())
    lst=list(map(int,input().strip().split()))
    m=max(lst)
    ls=[]
    lst.remove(m)
    ls.append(m)
    while(len(lst)>0):
        m=check(lst,m)
        lst.remove(m)
        ls.append(m)
    print(*ls)