def ucln(a,b):
    if a<b:
        a,b=b,a
    while b>0:
        cd=a%b
        a=b
        b=cd
    return(a)

t=int(input())
#3 4 2 1 5
for ii in range(t):
    n=int(input())
    a=[int(i) for i in input().split()]
    a.sort(reverse=True)
    uc=0
    maxx=0
    pos=0
    b=[a[0]]
    c=[a[0]]
    f=[False]+(n-1)*[True]
    for i in range(1,n):
        maxx=0
        pos=0
        for j in range(n):
            if f[j]:
                uc=ucln(c[i-1],a[j])
                if maxx<uc:
                   maxx=uc
                   pos=j
        f[pos]=False
        c.append(maxx)
        b.append(a[pos])
    for i in b:print(i,end=' ')
    print()