def gcd(a,b):
    if a>=b:
        if a%b==0:
            return b
        else:
            return gcd(a%b,b)
    else:
        if b%a==0:
            return a
        else:
            return gcd(a,b%a)
def fun(c,l):
    t=1
    p=0
    for i in l:
        v=gcd(i,c)
        if v>t:
            t=v
            p=i
    return [p,t]
for _ in range(int(input())):
    n=int(input())
    l=list(sorted(list(map(int,input().split()))))
    c=(l[-1])
    l.pop()
    m=[c]
    for i in range(n-1):
        u=fun(c,l)
        k=u[0]
        c=u[1]
        if k:
            m.append(k)
            l.remove(k)
        else:
            m+=l
            break
    print(*m,sep=" ")