def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
t=int(input())
while t:
    n=int(input())
    a=list(map(int,input().split()))
    i=0
    b=[0]*n
    mi=0
    while i<n:
        if a[i]>a[mi]:
            mi=i
        i+=1
    b[0]=a[mi]
    a[mi]=0
    cg=b[0]
    i=1
    while i<n:
        ci=0
        cans=0
        j=0
        while j<n:
            z=gcd(a[j],cg)
            if a[j] and z>cans:
                cans=z
                ci=j
            j+=1
        b[i]=a[ci]
        cg=cans
        a[ci]=0
        i+=1
    for x in b:
        print(x,end=' ')
    print()
    t-=1
