def gcd_naive(a, b):
    a,b=max(a,b),min(a,b)
    if b==0:
    	return a
    else:
    	a_= a%b
    return gcd_naive(b,a_)

def ans_f(a):
    b=[]
    c=[]
    b.append(max(a))
    c.append(b[0])
    a.remove(max(a))
    k=0
    while(len(a)>0):
        mx=0
        for i in a:
            if mx < gcd_naive(i,b[k]):
                mx=gcd_naive(i,b[k])
                temp=i
        k+=1
        b.append(temp)
        a.remove(temp)
        c.append(mx)
    return b



t = int(input())

ans= []
for i in range(t):
    n= int(input())
    a=[int(i) for i in input().split()]
    ans.append(ans_f(a))

for i in ans:
    print(*i)