# I'm always doing things I can't do. That's how I get to do them. Pablo Picasso

def gcd(a:int,b:int) -> int:
    return a if b==0 else gcd(b,a%b)

for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a.sort(reverse=True)
    i=0
    cm = a[0]
    while i<n-1:
        j=i+1
        m=i+1
        cm = gcd(cm,a[i])
        gm=1
        while j<n:
            g = gcd(cm,a[j])
            if g>gm:
                gm=g
                m=j
            j+=1
        if m!=(i+1):
            a[i+1],a[m]=a[m],a[i+1]
        i+=1

    print(*a)
