def hcfnaive(a,b): 
    if(b==0): 
        return a 
    else: 
        return hcfnaive(b,a%b)
t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    l=sorted(l)
    l=l[::-1]
    x=[0]*n
    x[0]=1
    ans=[l[0]]
    f=l[0]
    while f!=1:
        m=1
        r=0
        k=0
        for i in range(n):
            if x[i]==0 and hcfnaive(ans[-1],l[i])>1:
                if hcfnaive(f,l[i])>1:
                    if hcfnaive(f,l[i])>m:
                        m=hcfnaive(ans[-1],l[i])
                        r=l[i]
                        k=i
        if m>1:
            ans.append(r)
            x[k]=1
        f=m 
    for i in range(n):
        if x[i]==0:
            ans.append(l[i])
    print(*ans)