def computeGCD(x, y):

   while(y):
       x, y = y, x % y

   return x
for _ in range(input()):
    n=input()
    a=map(int,raw_input().split())
    a.sort()
    b=[a[-1]]
    done=[0 for i in range(n)]
    done[-1]=1
    cur=a[-1]
    for i in range(n-1):
        gg=0
        cc=0
        for j in range(n):
            if done[j]==0:
                u=computeGCD(cur,a[j])
                if u>gg:
                    gg=u
                    cc=j
        done[cc]=1
        cur=gg
        b.append(a[cc])
    for i in b:
        print i,
    print
