import math

t=int(input())
for _ in range(t):
    n=int(input())
    ls=list(map(int,input().split()))
    mi=max(ls)
    ind=ls.index(mi)
    ls[ind]=0
    b=[mi]
    cg=b[0]
    for i in range(1,n):
        ci=0
        cans=0
        for j in range(n):
            if(ls[j]!=0 and cans<math.gcd(cg,ls[j])):
                cans=math.gcd(cg,ls[j])
                ci=j
        b.append(ls[ci])
        cg=cans
        ls[ci]=0
        
    print(*b)